3 ms·
I don't really know what unsized_char would even mean, chars have a size, and str is not a sequence of chars. That said, I'm also not sure in the general case.
by steveklabnik 6y ago
I don't really know what unsized_char would even mean, chars have a size, and str is not a sequence of chars.
That said, I'm also not sure in the general case.
- yazaddaruvala 6y agounsized_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.