Paths
A path is a way of refering to named items.
Syntax
PathPrefix → ( self | super )? ::
Path → PathPrefix? IDENT ( :: IDENT )*
Example
mod utils {
fn sum(a: i32, b: i32) -> i32 {
a + b
}
}
fn foo() -> i32 { utils::sum(1, 2) }
let a: i32;
fn main() {
let a: i32 = 1; // Local variable
self::a = foo(); // Access the 'a' variable from the module
}
In the example above we have 4 paths
- Inside sum. Both
aandbare paths. utils::sumis a path composed of two segments:utilsandsumself::ais a path that refers to “the item a inside the current module”