compact_str icon indicating copy to clipboard operation
compact_str copied to clipboard

Support larger inline strings

Open ParkMyCar opened this issue 2 years ago • 6 comments

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

ParkMyCar avatar Jun 20 '22 19:06 ParkMyCar

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.

CAD97 avatar Jun 21 '22 17:06 CAD97

Maybe the other direction would be possible, too? 16 bytes with the capacity on the heap.

Kijewski avatar Jun 29 '22 13:06 Kijewski

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.

NobodyXu avatar Jun 29 '22 13:06 NobodyXu