Skip to content

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
@@ -0,0 +1,5 @@
mod string;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add copyright header to new files


/// 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.

fn grow(&mut self, alloc: &'a dyn Allocator, cap: usize, add: usize) {
debug_assert!(add > 0, "growing by zero makes no sense");

#[cfg(debug_assertions)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe this cfg is redundant with the debug_assert! macro.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh I see. alloc is for debug purposes only and so this macro won't compile without the cfg. Please disregard this comment.


/// 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?

/// View as a shared slice.
#[inline]
pub fn as_slice(&self) -> &[T] {
self
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a bit tricky/clever. I suppose it is using the Deref trait. I think it might be nice to be explicit and say Deref::deref() and DerefMut::deref_mut in as_mut_slice just to be clear. In those trait implementations, it is clear that this is using len to cap the length of the returned slice to the valid elements. Maybe it is helpful to mention that in the comments.


/// Appends all elements from a slice. It's basically a `memcpy`-append.
#[allow(clippy::mut_from_ref)]
pub fn extend_from_slice(&mut self, alloc: &'a dyn Allocator, other: &[T]) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we require T: Copy so that the ptr::copy_nonoverlapping will be valid?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Lol never mind. I see the constraint on line 281 now. Pelase disregard this comment.

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

2 participants