Skip to content

refactor!: use core::alloc::Allocator trait - #761

Open
morrisonlevi wants to merge 3 commits into
rust-lang:mainfrom
morrisonlevi:stable-allocator
Open

morrisonlevi wants to merge 3 commits into
rust-lang:mainfrom
morrisonlevi:stable-allocator

Conversation

@morrisonlevi

@morrisonlevi morrisonlevi commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

First off, I don't expect you'll actually merge this, at least not to main. Maybe to some v0.19 branch or something.

The goal is to see what it takes to enable using the core::alloc::Allocator trait which is available on Rust 1.100, without depending on any external crate (such as a new allocator-api2 version).

It's really not that much. The only apparenty difference between allocator-api2::alloc::Allocator and core::alloc::Allocator is the by_ref method, which hashbrown doesn't use. I assume there's a good reason there for why core did not add this method; I have not caught up on all the reading yet. But it means migration is really quite easy.

@clarfonthey

Copy link
Copy Markdown
Contributor

So, first, thank you for showing interest in helping out with hashbrown!

And you're right that we won't be merging this as-is. While we will be using the standard library Allocator API as part of rust-lang/goals#853, it seems very likely that due to MSRV concerns we'll be sticking with allocator_api2 for the time being, at least until the New™ version of the code is done and ready to be stabilised in std, so that folks depending on the library can get the up-to-date versions.

As far by_ref, the main reason, if I understand, was the method didn't really hold its weight, and we don't want to just add a method like that to every trait in std; adding it to Iterator was a mistake, IMHO.

I also would recommend any potential style or other minor improvements you make be submitted separately, since those I would be happy to merge.

@morrisonlevi

morrisonlevi commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the response! I understand the MSRV concern but I think there's a pretty easy solution: go to both 1.0 and 2.0. The 1.0 branch will use a conservative MSRV and be maintained for at least a year or so until other projects can bump their MSRV. Then 2.0 has the work based on the core::alloc::Allocator trait. As this patch shows, there's not much different so both should be pretty easy to maintain.

If that's not the plan... I'm interested in hearing the plan ^_^

@clarfonthey

Copy link
Copy Markdown
Contributor

Seems like a reasonable plan, although at least for now the main blocker to actually working more on the refactor is funding. I don't really want to commit to anything right now until there are more resources to actually work on this.

This branch has not been deployed

No deployments
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.

2 participants