mirror of
https://github.com/ahgamut/rust-ape-example.git
synced 2024-05-15 01:52:42 +00:00
26 lines
561 B
Rust
26 lines
561 B
Rust
// ./src/types/alias.md
|
|
|
|
|
|
// `NanoSecond`, `Inch`, and `U64` are new names for `u64`.
|
|
type NanoSecond = u64;
|
|
type Inch = u64;
|
|
type U64 = u64;
|
|
|
|
fn part0() {
|
|
// `NanoSecond` = `Inch` = `U64` = `u64`.
|
|
let nanoseconds: NanoSecond = 5 as U64;
|
|
let inches: Inch = 2 as U64;
|
|
|
|
// Note that type aliases *don't* provide any extra type safety, because
|
|
// aliases are *not* new types
|
|
println!("{} nanoseconds + {} inches = {} unit?",
|
|
nanoseconds,
|
|
inches,
|
|
nanoseconds + inches);
|
|
}
|
|
|
|
pub fn main() {
|
|
part0();
|
|
}
|
|
|