External Publication
Visit Post

Pre-RFC: Guarantee that pointers to `OsStr` has the same layout as pointers to `str`/`[u8]`

Rust Internals [Unofficial] May 26, 2026
Source

Not advocating for this, but hypothetically , the first 1-4 bytes of an OsStr-with-locale-info could be invalid UTF-8 to signify the presence of locale information, and valid UTF-8 to signify that no locale information was provided (supporting str: AsRef<OsStr>).

Maybe there would be some advantage of allowing the locale info to contain a pointer (precluding the use of [u8]). Or the locale info could just be encoded into a fancy [u8].

Edit: wait, that's about the backing data, not the pointer to it.

I suppose that storing locale info in the backing data would have the disadvantage of requiring a &mut OsStr instead of a &mut &OsStr to change the locale.

Discussion in the ATmosphere

Loading comments...