ParkMyCar / compact_str

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

fix: make sure suffix data when calling .align_to is empty #215

Closed ParkMyCar closed 2 years ago

ParkMyCar commented 2 years ago

Based on the docs from the stdlib, when calling align_to, it's possible for the entirety of the data to be returned in the prefix, or suffix slices:

This method splits the slice into three distinct slices: prefix, correctly aligned middle slice of a new type, and the suffix slice. The method may make the middle slice the greatest length possible for a given type and input slice, but only your algorithm’s performance should depend on that, not its correctness. It is permissible for all of the input data to be returned as the prefix or suffix slice.

This PR updates our use of .align_to to make sure the both the prefix slice and suffix slice are empty, thus guaranteeing the middle slice contains all of our data