> ## 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.

# Rust Use Declaration

The `use` declaration in Rust creates one or more local name bindings to items defined in a specific module path. While it eliminates the need to specify the fully qualified path for structs, enums, and functions, bringing a trait into scope via `use` is strictly required to access its methods using standard method-call syntax (`obj.method()`).

In modern Rust (2018 edition and later), paths in `use` declarations resolve similarly to standard paths: they are relative to the current module scope by default, or they resolve to external crates available in the **extern prelude**. Absolute paths typically begin with `crate::` or a specific crate name, but they can also begin with a leading `::` (e.g., `::std::collections::HashMap`). This leading `::` explicitly denotes an absolute path, which is sometimes necessary to disambiguate an external crate from a local module sharing the same name.

## Path Resolution

Rust provides specific keywords and syntax to dictate how the module tree is traversed when resolving a `use` path:

```rust theme={"dark"}
// Resolves to an external crate in the extern prelude
use std::collections::HashMap;

// Explicitly absolute path, bypassing any local module named `std`
use ::std::collections::HashMap as AbsoluteHash;

pub mod network {
    pub struct Connection;
}

pub mod configuration {
    pub struct Config;
}

mod child_module {
    // Absolute path from the root of the current crate
    use crate::network::Connection;

    // Relative path from the parent module
    use super::configuration::Config;

    pub mod internal {
        pub struct Helper;
    }

    // Explicit relative path from the current module
    use self::internal::Helper;

    // Implicit relative path from the current module scope
    use internal::Helper as ImplicitHelper;
}
```

## Aliasing and Anonymous Imports

The `as` keyword binds the imported item to a new local identifier. This is strictly a compile-time renaming mechanism used to resolve namespace collisions or to disambiguate items with identical names from different modules.

Additionally, the `_` identifier can be used to create an anonymous import. This is a critical pattern for traits: it brings a trait's methods into scope for method resolution without binding the trait's name to the local namespace, thereby preventing namespace pollution.

```rust theme={"dark"}
use std::fmt::Result;
use std::io::Result as IoResult;

// Anonymous import: brings Read methods into scope without binding the name `Read`
use std::io::Read as _;
```

## Nested Paths

To reduce boilerplate, multiple items sharing a common path prefix can be grouped using curly braces `{}`. The `self` keyword can be included within the braces to import the common prefix itself alongside its sub-items.

```rust theme={"dark"}
// Imports both BTreeMap and HashSet from std::collections
use std::collections::{BTreeMap, HashSet};

// Imports std::io and std::io::Write
use std::io::{self, Write};
```

## Glob Imports

The glob operator `*` brings all public items defined in a module, or all variants of an enum, into the current scope. When applied to a module, this creates bindings for every public struct, enum, trait, function, constant, static, type alias, macro, and submodule within the target module. When applied to an enum, it brings all of its variants directly into the local namespace.

```rust theme={"dark"}
// Imports all public items (structs, macros, etc.) from the module
use std::collections::*;

enum Status {
    Active,
    Inactive,
    Pending,
}

// Brings Active, Inactive, and Pending into the current scope
use Status::*;
```

## Re-exporting (Visibility)

Bindings created by `use` are private to the module they are declared in by default. Applying a visibility modifier to a `use` declaration creates a public or semi-public binding, effectively re-exporting the item. This allows external code to access the item through the current module's path rather than its original definition path. Restricted visibility modifiers like `pub(crate) use` or `pub(super) use` are commonly used to expose items only to specific scopes within the crate hierarchy without making them fully public.

```rust theme={"dark"}
mod internal {
    pub struct HiddenStruct;
    pub struct CrateStruct;
}

// Re-exports HiddenStruct to the public API of the current module
pub use internal::HiddenStruct;

// Re-exports CrateStruct only to the rest of the current crate
pub(crate) use internal::CrateStruct;
```

## Lexical Scoping

`use` declarations obey standard lexical scoping rules. When declared inside a block (such as a function body), the name binding is strictly limited to that block and shadows any identical names in the outer scope. Note that `use` statements are not valid associated items and cannot be placed directly inside an `impl` block, though they can be used freely inside the methods defined *within* an `impl` block.

```rust theme={"dark"}
const PI: f32 = 3.14;

fn calculate_precision() {
    // This binding is only valid within calculate_precision()
    // and shadows the outer f32 PI.
    use std::f64::consts::PI;
}
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Rust Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
