Last active
December 12, 2019 00:10
-
-
Save Drunpy/e510adc6be4a2d1f31ecb320f6ef7afa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Considering the app three: | |
- src | |
main.rs | |
- models | |
models.rs | |
- views | |
auth.rs | |
First you need to declare your module inside your main.rs | |
// main.rs | |
#[path = "./views/auth.rs"] | |
mod auth; | |
#[path = "./models/models.rs"] | |
mod models; | |
// Note the compiler will ask about a file called auth.rs or auth/mod.rs | |
// Since we're using folders we need to create a mod.rs inside it. | |
// Now our app three should be like bellow | |
- src | |
main.rs | |
- models | |
mod.rs | |
models.rs | |
- views | |
mod.rs | |
auth.rs | |
// And then inside mod.rs files declare its modules | |
// models/mod.rs | |
pub mod models; | |
// views/mod.rs | |
pub mod auth; | |
// Now to import something from your models.rs file to auth.rs | |
// models/models.rs | |
pub fn MyModel(){ | |
println!("{:?}", 'Hello from models.rs function); | |
} | |
// views/auth.rs | |
use crate::models::MyModel; | |
Special thanks to @mozilla_jebrosen:matrix.org |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment