rust-book/advanced_types/src/main.rs

17 lines
398 B
Rust

// Type alias, just gives a new name to the existing type.
// Considered the same type, even using the new name
type Kilometers = i32;
// A type alias is much more useful for a long, complex type
type Thunk = Box<dyn Fn() + Send + 'static>;
fn main() {
let x: i32 = 5;
let y: Kilometers = 5;
println!("x + y = {}", x + y);
let f: Thunk = Box::new(|| println!("hi"));
f();
}