module-concept

Rust Import a module and one of its members

Use self inside an import group to bind the module itself along with a member. This is useful when a signature uses qualified module types but also needs a trait name directly. Expected result (not executed): label Why: fmt names the module and Display names its trait. Common mistake: Expecting self in the group to import every member.

Formal Syntax & Structure

rust syntaxrust
use std::fmt::{self, Display};

Working Example

Example Snippetrust
use std::fmt::{self, Display};struct Label;impl Display for Label {    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "label") }}fn main() { println!("{}", Label); }
Rust Reference