Simple data types
- Integers:
i8
⮳,i16
⮳,i32
⮳,i64
⮳,i128
⮳,isize
⮳ - Unsigned:
u8
⮳,u16
⮳,u32
⮳,u128
⮳,usize
⮳ - Floating point:
f32
⮳,f64
⮳ - Boolean:
bool
⮳:true
,false
- Char:
let z: char = 'ℤ';
Unicode - Tuples:
let tup: (i32, f64, u8) = (500, 6.4, 1);
- Access via
let five_hundred = x.0;
- Destructuring via
let (x, y, z) = tup;
- Access via
- Arrays:
let a: [i32; 5] = [1, 2, 3, 4, 5];
allocated on the stack. access vialet first = a[0];
- A vector is a similar collection type provided by the standard library that is allowed to grow or shrink in size
- Unit (aka void):
()
- Type aliases:
type Kilometers = i32;
Handle overflows
- Wrap in all modes with the
wrapping_*
methods, such aswrapping_add
⮳. - Return the
std::option::Option::None
⮳ value if there is overflow with thechecked_*
methods. - Return the value and a boolean indicating whether there was overflow with the
overflowing_*
methods. - Saturate at the value’s minimum or maximum values with the
saturating_*
methods.