compact_str icon indicating copy to clipboard operation
compact_str copied to clipboard

Safer Repr?

Open goffrie opened this issue 8 months ago • 6 comments

I had an idea to avoid transmuting Reprs around by directly making use of the enum niche optimization. Basically, store ([u8; 23], LastUtf8Char) in Inline, restrict LastUtf8Char to only actual valid last-bytes for the Inline representation, then have Repr be an enum over Inline / Heap / &'static str / etc as desired, and the compiler will choose the discriminants for those variants.

See this Godbolt link.

goffrie avatar Oct 13 '23 20:10 goffrie