ParkMyCar / compact_str

A memory efficient string type that can store up to 24* bytes on the stack
MIT License
558 stars 41 forks source link

Make (re)allocations fallible #323

Closed Kijewski closed 8 months ago

Kijewski commented 8 months ago

The CI error in #321 is actually an implementation error. Once a CompactString gets so big that its capacity cannot be stored inline anymore, it will always be at least this big. This PR lets shrink_to() allocate a new Repr with a capacity that can be inlined.

To facilitate this change I made allocations and re-allocations fallible. As an added bonus better panic messages will be generated, mentioning the calling locations of the failing (re)allocations. And the user gets two new methods, try_with_capacity() and try_reserve, to manually handle out-of-memory cases.

Kijewski commented 8 months ago

LGTM, thanks for swift response to my review!

And thank you for your reviews! :)