Scalar Types

Scalar = single values: integers, floating-point, booleans, characters

Integer Types

2's compliment representation

signed range: -(2n - 1) to 2n - 1

unsigned range: 0 to 2n - 1

LengthSignedUnsigned
8biti8u8
16-biti16u16
32-biti32u32
64-biti64u64
128-biti128u128
archisizeusize

Overflow logic


#![allow(unused)]
fn main() {
let x: u8 = 220;
let (x, ok) = x.overflowing_add(50);
if ok {
		panic!("Overflowing!")
}
println!("{}", x)
}

Floating points

IEEE-754 single precision and double precision (f32 and f64)

Char

Single quotes

4 Bytes - unicode scalar value

U+0000 to U+D7FF and U+E000 to U+10FFFF

Literals representations

Number literalsExample
Decimal98_222
Hex0xff
Octal0o77
Binary0b1111_0000
Byte (u8 only)b'A'