Search code examples
importmodulerustrust-crates

How to import a file in a folder into a file in another folder in rust?


src
 I -- handlers
         I--- authhandler.rs
      models
         I--- account.rs
         I--- mod.rs

authhandler:

pub fn register(register: web::Json<RegisterRequest>) -> impl Responder {
   .........
}

account:

pub struct RegisterRequest {
    email: String,
    password: String
}

mod.rs

pub mod account;

I have tried to use use models::account::RegisterRequest;and crate models::account::RegisterRequest None of this worked out.

How can import RegisterRequest into authhandler?


Solution

  • I have found out that the RegisterRequest missed the use keyword and can be imported as:

    use crate::models::account::RegisterRequest;