3 ms·
unsized_char would be some phantom/opaque type that is not actually useable because it represents an object of variable length. e.g. Think of it as an enumerat
by yazaddaruvala 6y ago
unsized_char would be some phantom/opaque type that is not actually useable because it represents an object of variable length.
e.g. Think of it as an enumeration like :
unsized_enum unsized_char {
Char1(u8),
Char2(u8, u8),
Char3(u8, u8, u8),
}
let c: unsized_char = ...; // is a complied error: “cannot assign a variable stack size.” or something.
let parsed: &[unsized_char] = unsafe { /* parse some bytes */}; // this complies because the implementation of some hypothetical &[T + !Sized] appropriately abstracts the allocated memory region.
Unlike a normal enum it doesn’t always take 3 bytes of memory, it’s variable memory such that [unsized_char] might only take 1 byte if there is only 1 unsized_char::Char1 inside.
Of course this means that you can’t index into the slice because the boundary is not clear.
What I’m describing is not different than the internals of str. I’m just trying to armchair design a generic implementation such that str and slice are more unified.