use, as and re-exports in Rust
Bringing names into scope, renaming clashes, and re-exporting an API.
mod store {
pub mod inner {
pub struct Row(pub u32);
}
pub use inner::Row;
pub fn make() -> Row {
Row(7)
}
}
mod client {
use super::store::{self, Row};
pub fn read() -> u32 {
let row: Row = store::make();
row.0
}
}
use std::collections::HashMap as Table;
fn main() {
println!("{}", client::read());
let mut t: Table<&str, u32> = Table::new();
t.insert("rows", client::read());
println!("{:?}", t);
}
How it works
useshortens a path;asrenames it.super::refers to the parent module.pub usere-exports, flattening an internal tree.
Keywords and builtins used here
RowTableasfnletmainmakemodmutpubreadselfstrstructsuperu32use
The run, in numbers
- Lines
- 28
- Characters to type
- 405
- Tokens
- 145
- Three-star pace
- 100 tpm
At the three-star pace of 100 tokens a minute, this run takes about 87 seconds.
Step 2 of 3 in Modules & visibility, step 2 of 12 in Modules, tests & macros.