Integer types
Rust has many integer sizes:
| Type | Signed | Bytes |
|---|---|---|
i8 | yes | 1 |
i16 | yes | 2 |
i32 | yes | 4 |
usize | unsigned | pointer size |
usize is for sizes and indices. i32 is the default choice for counting.
Type conversion
Convert explicitly with methods:
let s = "42";
let n: i32 = s.parse().unwrap();
let back = n.to_string();
parse() converts a string into a number; unwrap() extracts the value or panics on failure. to_string() converts a number back to a string.