Guide 18 of 53
Hierarchical import lists
Group related imports while preserving paths, aliases and visibility.
Group imports under their shared prefix and keep each source path visible. Nested lists accept aliases, self and globs. A pub use list retains the visibility of each original declaration; grouping never makes a private item public.
// Group related imports while keeping aliases on individual leaves.
mod tools {
pub mod numbers { pub fn twice(value: int) -> int { value * 2 } }
pub mod labels { pub fn label(value: int) -> str { "total: {value}" } }
}
use tools::{numbers::{twice}, labels::{label as display}}
print(display(twice(6))) // expect: total: 12The formatter preserves the authored list. Diagnostics and editor navigation still point to each import leaf.
DOCS / FEEDBACK
Did this page leave a question?
Tell us where the explanation lost you. Documentation is part of the language experience.