A glob import in Rust utilizes the wildcard operator (Documentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
*) within a use declaration to bring all accessible items defined in a specified module, crate, or enum into the current namespace. This mechanism binds multiple identifiers to the local scope simultaneously without requiring explicit, itemized declarations.
Mechanics and Behavior
Visibility Rules A glob import strictly respects Rust’s privacy boundaries. It brings items into scope based on their visibility modifiers relative to the importing module. This includes items marked withpub, as well as items with restricted visibility modifiers (such as pub(crate), pub(super), or pub(in path)), provided the importing module resides within the permitted visibility scope. Private items within the target module remain inaccessible and are ignored by the glob operator.
Enum Variants
When applied to an enum type, a glob import brings all of the enumeration’s variants into the current scope. Because enum variants inherit the visibility of the enum itself, a glob import on any accessible enum will successfully bind all of its variants locally, allowing them to be referenced without their type namespace.
Shadowing and Precedence
Rust’s module system resolves name collisions between glob imports and explicit imports through shadowing rather than immediate compilation errors.
- Explicit over Glob: An explicitly imported item or a locally defined item will always shadow an item of the same name brought in via a glob import.
- Glob vs. Glob: If two separate glob imports bring in items with identical names, the compiler will not error at the
usestatements. However, if the ambiguous identifier is actually referenced in the code, the compiler will throw an ambiguity error (E0659).
Master Rust with Deep Grasping Methodology!Learn More





