Skip to content

Add allocator API support to basic Slotmap type#152

Open
TooManyLimits wants to merge 6 commits into
orlp:masterfrom
TooManyLimits:master
Open

Add allocator API support to basic Slotmap type#152
TooManyLimits wants to merge 6 commits into
orlp:masterfrom
TooManyLimits:master

Conversation

@TooManyLimits

@TooManyLimits TooManyLimits commented May 24, 2026

Copy link
Copy Markdown

Allows the basic SlotMap type to take an extra A: Allocator generic which will be used for allocation. There are 3 modes depending on the features selected:

  • Default features: Same as the current impl. The A: Allocator is just a dummy type which does nothing, and the real impl uses the same alloc::vec::Vec as currently.
  • nightly feature: Uses the nightly allocator API Allocator trait
  • allocator-api2 feature: Uses the allocator-api2 crate to implement the allocator api in stable Rust, without needing nightly

Currently the impl only targets the SlotMap type defined in basic.rs, but it could be implemented for the other maps similarly.

Please let me know if you have questions about my impl or suggestions for things that should change. Thanks!

Edit: I heard that apparently there's movement happening recently towards stabilizing allocator API. If that happens, this PR would be essentially useless, since most of its functionality is in switching allocator impls between feature sets. So if you believe it'll be stable soon, then it would be better to ignore/close this PR, and use the API in a normal, sane way without the weird config/modules/newtype hacks.

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.

1 participant