LongHike
LongHike

Reputation: 4460

Getting "use of undeclared type or module" when accessing impl module

I have this module:

src/adapters.rs

use super::db::{init_connection, models};
use actix_web::Responder;
use diesel::r2d2::{ConnectionManager, Pool};
use diesel::MysqlConnection;

pub struct Basic {
   pool: Pool<ConnectionManager<MysqlConnection>>,
}

impl Basic {

    pub fn new() -> Basic {
        Basic {
            pool: init_connection().unwrap(),
        }
    }

    pub async fn admin_index(&self) -> impl Responder {
        "API Admin"
    }
}

and I'd like to call the instance method admin_index from the module:

src/routes.rs

like this:

use actix_web::{web, HttpResponse, Responder};
use super::adapters::Basic;

pub fn create(app: &mut web::ServiceConfig) {

    let basicAdapters = Basic::new();

    app
        .service(web::resource("/").to(|| HttpResponse::Ok().body("index")))
        .service(
            web::scope("/api")
                .service(
                    bweb::scope("/admin")
                        .route("/", web::get().to(basicAdapters::admin_index))
                )
}

but I keep getting:

error[E0433]: failed to resolve: use of undeclared type or module `basicAdapters`

.route("/", web::get().to(basicAdapters::admin_index))
                          ^^^^^^^^^^^^^ use of undeclared type or module `basicAdapters`

I don't understand why I am getting this error message, because basicAdapters is obviously declared by

let basicAdapters = Basic::new();

Any help is appreciated.

Upvotes: 0

Views: 991

Answers (1)

trent
trent

Reputation: 28075

:: is a namespace resolution operator, and basicAdapters isn't a namespace.

To call a method on a value, use the . operator:

web::get().to(basicAdapters.admin_index())

Upvotes: 2

Related Questions