STD Library (see more)
OptionandResultused for optional values and error handling respectively.Vecis a growableVector.Stringis a growable UTF-8 encoded string.HashMapis a hash map with keys and values, with a configurable hash algorithm.Boxis a owned pointer to a value in the heap.Rcis a reference counted pointer to a value in the heap.
Modules
Same as impl allow to namespace functions to a type, mod allows to namespace functions
and types. The syntax is as follows:
mod foo {
pub fn do_something() {
println!("In the foo module");
}
}
mod bar {
pub fn do_something() {
println!("In the bar module");
}
}
fn main() {
foo::do_something();
bar::do_something();
}
The module content are private by default, so the pub keyword is required
to make them public.
mod garden;
The garden mod can be found at:
src/garden.rs(modern Rust 2018 style)src/garden/mod.rs(older Rust 2015 style)
Similarly, a garden::flowers module can be found at:
src/garden/flowers.rs(modern Rust 2018 style)src/garden/flowers/mod.rs(older Rust 2015 style)
The crate root is in:
src/lib.rs(for libraries)src/main.rs(for binaries)