Alloc-WG
An attempt to collect several proposals of rust-lang/wg-allocators into a MVP.
Changes regarding the current Alloc
trait
-
The first thing to notice is, that
Alloc
was renamed toAllocRef
in order to show that they are typically implemented for a reference or smart pointer or ZST, not directly for the type that actually holds the allocator’s state.Issue: rust-lang/wg-allocators#8
-
AllocRef
was split up intoAllocRef
,DeallocRef
, andReallocRef
to make more flexible allocators possible.Issue: rust-lang/wg-allocators#9
-
The allocators has to be associated with
BuildAllocRef
. It is related to the allocator traits similar howBuildHasher
is related toHasher
. Although the signatures are different, it makes an even more flexible allocator design possible.Issue: rust-lang/wg-allocators#12
-
Added an associative error type to
AllocRef
. Besides adding the possibility of returning additional information on allocation failure, it's also possible to split the usage of theAllocRef
into a fallible and an infallible case. Personally I think this is a pretty big deal, as kernel programmer can rely on allocation, which will never fail. If an allocation can fail, only atry_*_in
method may be available. To maintain backwards compatibility,AbortAlloc
was introduced.AbortAlloc
wraps another allocator, but aborts on OOM thusAbortAlloc<Global>
may be used as default allocator forBox
orVec
. To realize this,AbortAlloc
implementsAllocRef<Error=!>
.Issue: rust-lang/wg-allocators#23
-
The new layout type
NonZeroLayout
was introduced. Currently, implementors ofAlloc
can chose to allow zero-sized allocation so in a generic context it's impossible to rely on this, so banning zero-sized allocation is a possible step to prevent this. This also removesunsafe
fromAllocRef::alloc
andAllocRef::alloc_zeroed
, and unlocks the possibility to move the extension API likealloc_array
into a separate trait.Issue: rust-lang/wg-allocators#16
Currently associated containers
-
Box
Missing Items:FromIterator<A> for Box<[A]>
asVec
is not implemented yet.- specialization of sized iterators as it's not possible for downstream crates.
- Limited
T: Copy
forFn
-traits as it's not possible for downstream crates.
-
RawVec
(Only methods and basic traits)
License
Alloc-WG is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See LICENSE-APACHE and LICENSE-MIT for details.