Rust literals and variables

Literals

Integer literals

Decimal literals:

12345
12_345
012345

Hex, oct and bin literals

0xff
0o77
0b110

Integer literals in a given format

can do

i8, i16, i32, i64, i128
u8, u16, u32, u64, u128

5i32
0b101i32

Assignment and type notations

Type annotations

let x:u32 = 2

Can split out declaration and definition.

let x:u32
x = 2

Mutable variables

Can’t do this because default immutableimmutable.

let x = 1
x = x + 1

can do

let x = 1
let x = x + 1

this is shadowing the variable?

We can make variables mutable.

let mut x = 1
x = x + 1

Const

Different to immutable because const are known at compile-time, whereas immutables may not be known until run time.

const x = 1

String literals

byte (u8?): b'A'

Float literals

f32, f64