usize and isize types in Rust

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

Most numeric data types in Rust are fairly straightforward to understand. i.e. u8, u16, u32, i8, i16, i32.

The prefix (i or u) represents whether the integer is signed or not, or simply that it can hold negative values or not; And the suffix (8, 16,32) represents the number of bits allocated.

So, a u32 just means a numeric variable that cannot hold negative values and can represent at most 2^32 states (which means a max value of 2^32 = 4294967296).

usize and isize

The usize and isize types differ from these other types because the number of bits allocated in them is based on the architecture of the machine.

So, they can be assigned a different number of bits based on the machine they are running on.

In a 32-bit machine, 
      usize = u32
      isize = i32

In a 64-bit machine,
      usize = u64
      isize = i64

This basically means their values depend on the number of bits it takes to describe a memory location on the host machine.

Since, in a 64-bit machine, we would require 64 bits (or 8 bytes) to refer to a memory location, the value of usize will be equivalent to u64. That's why standard library functions will use usize for a variable that needs to store a pointer.

Since memory locations are always referenced using positive numbers, usize is used instead of size for them.

The good thing is, you don't need to keep track of all this since the Rust compiler treats usize, u64 and u32 as different types. So, even on a 64-bit machine, it will give a compile time error if you try to compare a u64 to a usize.