Rust has four primary scalar types:
Length | Signed | Unsigned |
---|---|---|
8-bit | i8 | u8 |
16-bit | i16 | u16 |
32-bit | i32 | u32 |
64-bit | i64 | u64 |
128-bit | i128 | u128 |
arch* | isize | usize |
The "arch" length is system architecture dependent.
Number Literals | Example |
---|---|
Decimal | 12_345_678 |
Hex | 0xfe |
Octal | 0o76 |
Binary | 0b1111_0000 |
Byte (u8 only) | b'A' |
Length | Type |
---|---|
32-bit | f32 |
64-bit | f64 |
Note: Rust defaults all floats to f64
.
A boolean in Rust is either true
or false
and takes up one byte. The type is specified with bool
.
The character type in Rust is a four byte Unicode Scalar Value. For example:
fn main() {
let c = 'z';
let z = 'ℤ';
let laughing_crying_face = '😂';
}