module-concept
Rust Crate-root and external absolute paths
In Rust 2024, crate:: starts from the current crate root. A leading :: resolves a crate name through the extern prelude, rather than automatically referring to the current crate root. These explicit paths help disambiguate names. Expected result (not executed): 12 notes.txt Why: The two path roots select the current crate and the standard library respectively. Common mistake: Assuming ::config always means a module at the current crate root.
Formal Syntax & Structure
rust syntaxrust
crate::module::item; ::std::path::PathWorking Example
Example Snippetrust
mod config { pub const LIMIT: u32 = 12; }mod job { pub fn limit() -> u32 { crate::config::LIMIT } }fn main() { let p = ::std::path::Path::new("notes.txt"); println!("{} {}", job::limit(), p.file_name().unwrap().to_str().unwrap()); }