liveBook · Manning

Import alias

As explained in Refactoring to Rust

An import alias is an alternate local name assigned to an imported Rust item or path.

An import alias gives an imported Rust item or path a shorter local name. Using `pub use` also re-exports the item, creating a public-facing name at the crate root. section 5.2.2 section 5.2.1

Shortening a nested type path

Replace repeated `crate::day_kind::DayKind` imports with a root alias: `pub use crate::day_kind::DayKind;` Other modules can then write `use crate::DayKind;`. Both names refer to the same item, but the second path is shorter.

Re-exports can hide a module hierarchy from users of a library. A deeply nested function can be exposed through a short path, while implementation modules remain private or crate-visible. section 5.2.2

How Refactoring to Rust covers it

How deep it goes
Explains local imports, `pub use`, re-exports, module hierarchy, and visibility, but stops short of broader aliasing forms.
Examples
Uses a greeter application’s `DayKind` imports and a forest crate’s deeply nested `enter` function.
What it assumes
Assumes basic Rust modules and paths while teaching path shortening, re-exporting, and visibility through incremental examples.
What you can do after
Apply it via Rust `use` and `pub use` to shorten imports and present controlled crate-root names.
How it connects
Connects import aliases with Rust paths, modules, re-exports, visibility, and public API design.

Also explained in

Compare how 3 books explain import alias →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Refactoring to Rust. The section links point to the parts of the book it draws on.