beginnerBasics
Type Aliases
Use type aliases to create shorter names for complex types.
Type Aliases
Use type aliases to create shorter names for complex types.
Difficulty
Beginner
Code
rust
type Kilometers = i32;
type Thunk = Box<dyn Fn() + Send + 'static>;
fn main() {
let distance: Kilometers = 5;
println!("{} km", distance);
let f: Thunk = Box::new(|| println!("called!"));
f();
}Explanation
Type aliases create shorter names for complex types. They are syntactic sugar, not new types.
Key Concepts
- Read the code carefully and understand the data flow
- Try modifying the example to see how it changes behavior
- Run this code in the Rust Playground
Related Topics
Browse more examples in the basics category to build a complete understanding of this topic.