-
Notifications
You must be signed in to change notification settings - Fork 292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Default implementations for heap types which support the unstable allocator API #653
Comments
Perhaps some of the other maintainers have different opinions, but my feeling is not to have nightly APIs in the bytes crate. Nightly features tend to have churn, and once it stabilizes, the crate versions that supported it as a nightly feature stop working. It's fine to experiment, but I wouldn't do so and publish such a fundamental crate as bytes. Once the libstd developers stabilize it, we can adopt it. |
Absolutely agreed, unstable feature support in public crates does tend to have a code smell to it. That being said, the If we want to support the allocator API (i.e. for no_std projects), we can alternatively go the route of using that third-party Link to a similar discussion on hashbrown: rust-lang/hashbrown#417 |
I'm sorry, but we don't have enough maintainer bandwidth to support something unstable that may require changes in the future. |
Understandable, and thank you for the continued maintenance. Since there is a reasonable alternative here to wrap the allocator types in local structs and then re-implement |
Rust has introduced new generic arguments to collection and other heap types such as
Vec
andBox
called the "allocator_api". The idea behind this new API is to allow for custom allocators to manage the memory of these types on the heap.This feature is currently marked as unstable on Rust nightly, but is becoming more widely used, especially in no_std environments where allocations should be marked as more explicit and controlled.
Currently, the
bytes
crate has default implementations forBuf
andBufMut
on some heap types (such asBox
andVecDeque
), but does not support custom allocators for these default implementations. For users, it is then impossible to automatically implement these traits for the heap types that support custom allocators, since both the trait and the heap type are defined outside of the current crate. This would require a wrapper struct to implement within another crate, which is inconvenient and muddies the code with extra types.The solution to this is a quite simple feature addition, where the
bytes
crate adds a new feature calledallocator_api
that conditionally enables the Rust nightly/unstableallocator_api
feature and compiles new default implementations for the heap types already present.This new
allocator_api
feature will be disabled by default for thebytes
crate. Users who wish to opt-in to this feature can enable it manually, until the allocator_api feature is stable.I've written up a PR to address this feature request and will attach it to this issue.
The text was updated successfully, but these errors were encountered: