Description
Rust has introduced new generic arguments to collection and other heap types such as Vec
and Box
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 for Buf
and BufMut
on some heap types (such as Box
and VecDeque
), 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 called allocator_api
that conditionally enables the Rust nightly/unstable allocator_api
feature and compiles new default implementations for the heap types already present.
This new allocator_api
feature will be disabled by default for the bytes
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.