compact_str
compact_str copied to clipboard
Support larger inline strings
With the recent advancements in const generics, it's theoretically possible to support a CompactString
with a user defined size that is > 24, e.g. 32, 40, 48 bytes long. We should try doing this and playing with an API
The way to do so would be to switch Repr
(back) to a (*mut (), [MaybeInit<u8>; N], NonMaxU8)
layout. However, this N
probably wants to be { max(CONFIGURED_INLINE_SIZE, 24) - size_of::<*mut ()>() - size_of::<NonMaxU8>() }
, so still requiring const dependent types (which aren't stable yet) or typenum to polyfill.
Typenum supports lifting and lowering to/from plain const generics, so the API can still be pure const generics even if the implementation uses typenum to do math to them.
Maybe the other direction would be possible, too? 16 bytes with the capacity on the heap.
Maybe the other direction would be possible, too? 16 bytes with the capacity on the heap.
Nah, I don't think this is a good idea.
That would make CompactString
incompatible with String
.
Conversion from String
or to it would have to take extra time to realloc/rewrite the layout.
It would also impact ToCompactString
implementation, which also relies on O(1)
conversion from String
.