Survey: Associated error type on `Allocator`
⚓ Rust 📅 2026-06-03 👤 surdeus 👁️ 1Hello everyone,
There has been some recent progress on the stabilization of Allocator. It looks like it might be possible to have an associated error type on std::alloc::Allocator, something like this:
unsafe trait Allocator {
type Error: TraitBoundsYetToBeDecided;
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, Self::Error>;
...
}
Hypothetically, if this was possible without any drawbacks, would you have a use for it? If you have ever worked with the allocator api, please fill out this poll and optionally respond below with your use case. Select all kinds of error types you would find useful. Assume that the Layout for which allocation failed is available by other means and does not need to be in your error type.
- I have no use for this. The existing zero sized
AllocErroris good enough for everything I do. - An uninhabited type (never type):
!orInfallible. - An error that is at most
usizein size, e.g. to communicate error codes. - An error type that is larger than
usizeon at least some targets you care about.
If you do share a use case, please also specify if it is:
- something that you would have used in a concrete project you have worked on or are working on
- something that you think would be nice, but have not needed so far
1 post - 1 participant
🏷️ Rust_feed