The type that consists of a pointer and length is &[u8]
.
What is a type? I think of types as a property a region of memory may or may not have, and that these properties are something you can prove to be true at compile time.
If you know that a region of memory has type u32
, you know that the region has length 4. You also know that you can read the memory, i.e. it can't be deallocated.
If you know that a region of memory has type &u32
, you know that it has size 8. You also know that if you interpret the bytes as a pointer and dereference it, you will find a region of memory of type u32
. This means that e.g. you know that the 8 bytes are not all zeros, because then you could not dereference it and find an u32
, as the zero address is not allocated.
If you know that a region of memory has type [u8]
, you know that it contains a sequence of values of type u8
of some length. This type does not enforce any length on the region you make the claim about. Since the u8
type requires the memory to be allocated, you in turn know this about the entire region.
If a region of memory has type &[u8]
, you know that this region has length 16 bytes, and that the region starts out with a pointer followed by an usize. Additionally, you know that the other region starting at the pointer and having the specified length must have the type [u8]
, which e.g. means that you know that the memory is allocated.