Conversation
08690f0 to
ca6c7d8
Compare
|
|
||
| /// See [`BVec::into_std_vec()`]. | ||
| pub fn into_std_string(self) -> String { | ||
| unsafe { String::from_utf8_unchecked(self.vec.into_std_vec()) } |
There was a problem hiding this comment.
Why not use from_utf8 and propagate the Utf8Error like the next function.
There was a problem hiding this comment.
Since self is guaranteed to be valid UTF8 it doesn't need to re-validate it when converting it into a String.
BTW these 4 functions that convert between String<>BString and Vec<>BVec are essentially a small experiment I've been doing, where I see if my code works with the standard heap allocator. It actually helped me find a bug too. 😅
|
|
||
| /// Consume the string, returning a `&mut [T]` that lives as long as the borrowed memory. | ||
| #[inline] | ||
| pub fn leak(self) -> &'a mut [T] { |
There was a problem hiding this comment.
Although this is called leak, it does not seem to actually leak memory. It also does not seem to do anything useful compared to as_mut_slice. Maybe we don't need it?
There was a problem hiding this comment.
I called it so to make this function interchangeable with the standard Vec.
More importantly, if you call push and it reallocates the backing memory, any previous slice reference becomes stale memory. Because of this, the other slice methods return data tied to the self lifetime. Only this method ties it to 'a, and only because it destroys the self instance.
|
Thanks for the review @qbradley! |
Allocatoris not stable after a decade? Fine.We'll make our own
Allocator, with... uh..."high-stakes gamification and concierge-level support services"!
Closes #44