Having issues with mod multi files

pub mod users;

pub use users::details;

fn main() {
	details::say_details();
	println!("Hello, Yelsin");
}

user.rs

pub mod users {
	pub mod details {
		pub fn say_details() {
			println!("His name is Yelsin, He his a BOY");
		}

		pub fn profession(name: String) {
			println!("He his a {:?}", name);
		}
	}
}

How can you guys help me with this?

Get rid of the pub mod users { } in the second file, and make sure that file is called users.rs (you wrote user.rs here).

Basically, this:

pub mod users;

Expands to this:

pub mod users {
    /* contents of users.rs, exactly as written */
}
2 Likes

The second file is users.rs not user.rs

Im still getting same error let me show you the screenshotScreenshot%20from%202019-06-08%2023-50-34 Screenshot%20from%202019-06-08%2023-50-59

No, that is not what was explained. Replace the contents of users.rs with the following:

pub mod details {
	pub fn say_details() {
		println!("His name is Yelsin, He his a BOY");
	}

	pub fn profession(name: String) {
		println!("He his a {:?}", name);
	}
}

Do not wrap it in a pub mod users block. This is predefined when you say pub mod users; in main.rs.

2 Likes

In addition to @OptimisticPeach, we can follow the new convention of using namespace use crate::users::details.

1 Like

@ExpHP @OptimisticPeach @prataprc, I really appreciate you guys. Thanks
@ExpHP you also solved the problem am the one that didn’t get the explanation well.

Thanks to the rust community.