Rust - Types - Scalar Types


Rust has four primary scalar types:

  • Integers
  • Floating-Point Numbers
  • Booleans
  • Characters
Integer Types
Integer 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.

Integer Literals
Number Literals Example
Decimal12_345_678
Hex0xfe
Octal0o76
Binary0b1111_0000
Byte (u8 only)b'A'
Floating-Point Types
Floating-Point Types
Length Type
32-bitf32
64-bitf64

Note: Rust defaults all floats to f64.

The Boolean Type

A boolean in Rust is either true or false and takes up one byte. The type is specified with bool.

The Character Type

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 = '😂';
}