-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move modules examples to separate .rs files
- Loading branch information
Showing
4 changed files
with
56 additions
and
33 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#![allow(unused_imports, dead_code)] | ||
|
||
use std::collections::HashMap; | ||
use std::fs::File; // `File` without prefix is now available in the scope // For code from an external crate, the absolute path begins with the crate name - here, the standard `std` library | ||
|
||
use std::collections::*; // Glob - all public objects | ||
|
||
use std::io::{self, Write}; | ||
use std::{cmp::Ordering, fmt}; // Combining multiple use lines together | ||
|
||
mod utils { | ||
pub fn insert_use() {} | ||
} | ||
use crate::utils::insert_use; // Absolute path - for code from the current crate, it starts with the literal crate. | ||
|
||
mod a { | ||
pub mod b {} | ||
} | ||
use self::a::b; // A relative path starts from the current module and uses self, super, or an identifier in the current module. | ||
|
||
mod c { | ||
use super::a; // We can construct relative paths that begin in the parent module, rather than the current module or the crate root, by using super at the start of the path. | ||
} | ||
|
||
use std::fmt::Result; | ||
use std::io::Result as IoResult; // Alias | ||
|
||
mod front_of_house { | ||
pub mod hosting {} | ||
} | ||
pub use crate::front_of_house::hosting; // Reexporting - Now that this pub use has re-exported the hosting module from the root module, external code can now use the path <crate>::hosting::add_to_waitlist() instead. | ||
|
||
fn main() {} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use front_of_house::hosting; | ||
|
||
mod front_of_house { | ||
pub mod hosting { | ||
pub fn add_to_waitlist() {} | ||
} | ||
} | ||
|
||
fn eat_at_restaurant() { | ||
hosting::add_to_waitlist(); | ||
} | ||
|
||
fn main() { | ||
eat_at_restaurant(); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use std::collections::HashMap; | ||
|
||
fn main() { | ||
let mut _map: HashMap<u32, String> = HashMap::new(); | ||
} |
This file contains 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