keyword
Rust type: declare an alias for a type
A type alias introduces another name for an existing type. It can improve readability without creating a separate nominal type. Expected output (not executed): 250 Why: Cents is another name for u32, so the multiplication uses integer arithmetic. Common mistake: An alias does not prevent mixing values with the underlying type. A newtype struct can enforce that distinction.
Formal Syntax & Structure
rust syntaxrust
type Alias = ExistingType;Working Example
Example Snippetrust
type Cents = u32;fn total(price: Cents, quantity: u32) -> Cents { price * quantity }
fn main() { println!("{}", total(125, 2));}