Skip to content

Remove allocator_api#762

Merged
lhecker merged 4 commits intomainfrom
dev/lhecker/stable-allocator-api
Feb 12, 2026
Merged

Remove allocator_api#762
lhecker merged 4 commits intomainfrom
dev/lhecker/stable-allocator-api

Conversation

@lhecker
Copy link
Member

@lhecker lhecker commented Feb 10, 2026

Allocator is not stable after a decade? Fine.
We'll make our own Allocator, with... uh...
"high-stakes gamification and concierge-level support services"!

image

Closes #44

@lhecker lhecker requested review from DHowett and qbradley February 10, 2026 17:32
@lhecker lhecker force-pushed the dev/lhecker/stable-allocator-api branch from 08690f0 to ca6c7d8 Compare February 10, 2026 17:33

/// See [`BVec::into_std_vec()`].
pub fn into_std_string(self) -> String {
unsafe { String::from_utf8_unchecked(self.vec.into_std_vec()) }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use from_utf8 and propagate the Utf8Error like the next function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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] {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@lhecker
Copy link
Member Author

lhecker commented Feb 12, 2026

Thanks for the review @qbradley!

Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the delta, approved

@lhecker lhecker merged commit 6c79a1d into main Feb 12, 2026
6 checks passed
@lhecker lhecker deleted the dev/lhecker/stable-allocator-api branch February 12, 2026 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider limiting use of nightly features

3 participants