Open
Description
When adding allocators, many current traits become useless. Those traits should be either extended to support allocators or orthogonal traits should be added.
-
Default
: AddDefaultIn
:pub trait DefaultIn { type Alloc: Alloc; fn default_in(allocator: Self::Alloc) -> Self; }
-
FromIterator
: AddFromIteratorIn
:pub trait FromIteratorIn<T, A: Alloc>: Sized { fn from_iter_in<I: IntoIterator<Item = T>>(iter: I, allocator: A) -> Self; }
-
Iterator
: Addcollect_in
:pub trait Iterator { // ... #[inline] #[must_use = "if you really need to exhaust the iterator, consider `.for_each(drop)` instead"] fn collect_in<T: FromIteratorIn<Self::Item, A>, A: Alloc>(self, allocator: A) -> T { FromIteratorIn::from_iter_in(self, allocator) } }
-
(Try)From
and(Try)Into
: Add(Try)FromIn
and(Try)IntoIn
:pub trait FromIn<T> { type Alloc: Alloc; fn from_in(t: T, allocator: Self::Alloc) -> Self; } pub trait IntoIn<T> { type Alloc: Alloc; fn into_in(self, allocator: Self::Alloc) -> T; } impl<T, U: FromIn<T>> IntoIn<U> for T { type Alloc = U::Alloc; fn into_in(self, allocator: Self::Alloc) -> U { U::from_in(self, allocator) } }