[−][src]Crate loaf
Why have a slice when you can have a loaf?
What this is
Sometimes you know that a slice must have at least one element in it,
but Rust forces you to do "last minute decision" by unwrap()
ing Option
from for example first()
for split_first()
methods.
Loaf
guarantees to have at least one element by its definition.
Safety
Currently unsafe code is only used to cast between [T]
and Loaf<T>
pointers.
Rust's pointers to unsized types consist of two elements: pointer to data and
length of the unsized part
So a fat pointer to [T]
has a pointer to the beginning of buffer and its length
Loaf
has an one element array of T
and [T]
and because of it when casting
from slice pointer, the pointer is kept, but the length is decremented
(remember, fat pointer keeps length of the unsized part)
The one element array is guaranteed to be first, because unsized types must be at the end of struct.
Structs
LoafN |