Skip to content

Make the allocator_api and allocator-api2 features compatible#286

Closed
AlexanderPortland wants to merge 1 commit intofitzgen:mainfrom
AlexanderPortland:main
Closed

Make the allocator_api and allocator-api2 features compatible#286
AlexanderPortland wants to merge 1 commit intofitzgen:mainfrom
AlexanderPortland:main

Conversation

@AlexanderPortland
Copy link
Copy Markdown

In some niche use cases, it seems useful for &Bump to implement both core::alloc::Allocator and allocator-api2::alloc::Allocator at once. This has come up for me specifically when using data structures from different crates which were generic over those differing allocator traits.

However, simply enabling both the "allocator_api" and "allocator-api2" features doesn't work because there's only a single impl block that's conditionally compiled if either feature is enabled. This causes the "allocator_api" implementation to overwrite the "allocator-api2" one.

If this is intended behavior, would it be alright if I add a note to the README to that effect to help others who might be confused like I was initially? And if not, this PR just introduces two separate impl blocks so that &Bump can satisfy both traits simultaneously.

@fitzgen
Copy link
Copy Markdown
Owner

fitzgen commented Jul 24, 2025

The allocator_api2::alloc::Allocator trait should become just a re-export of the core::alloc::Allocator trait when using nightly and enabling the unstable allocator-api Rust feature. If things aren't working as expected, happy to help clarify and brainstorm fixes.

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