Open sollyucko opened 4 years ago
I was able to implement this API for a typestate-ish-based safe upwards bump allocator:
Playground: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=28dcb72cf6b64421b7302b1ed0183448
I've been waiting for some other people in the WG to respond to this issue, because I didn't fully comprehend the need for a solution to the described problem.
As no one has responded yet, I'll give my two cents. As far as I understand, the goal of the AllocRef
API is to provide a low-level allocator API that operates on bytes. External crates are free to implement type-based APIs, but it is unnecessary for it to be part of std.
Rationale
unsafe
code than necessary.Core traits
These traits do not currently include a generic way to create instances; this is expected to be done through methods on allocators. Additionally, these traits do not control zeroing; this is expected to depend on the type of the allocator. (Are there any cases where creation/resizing is sometimes non-zeroing and sometimes zeroing, for the same value?)
Instances of these traits should free their memory on drop.
Additional trait
This is used by types like
Rc
andArc
.Usage examples
See also