- type
Type alias
- We can use the type keyword to create aliases to existing types. This can help us in reading the code, but Rust does not do any enforcement.
- As you can see in the following example we can pass arguments to a "different" type as long as it is an alias to the same type.
- type
examples/other/type-alias/src/main.rs
type Meters = u32; type Kilograms = u32; fn main() { let m: Meters = 3; let k: Kilograms = 4; calc(m); calc(k); } fn calc(y: Meters) { println!("{y}"); }
3 4