pub trait FromIteratorIn<A> {
    type Alloc;

    // Required method
    fn from_iter_in<I>(iter: I, alloc: Self::Alloc) -> Self
       where I: IntoIterator<Item = A>;
}
Expand description

A trait for types that support being constructed from an iterator, parameterized by an allocator.

Required Associated Types§

source

type Alloc

The allocator type

Required Methods§

source

fn from_iter_in<I>(iter: I, alloc: Self::Alloc) -> Selfwhere I: IntoIterator<Item = A>,

Similar to FromIterator::from_iter, but with a given allocator.

let five_fives = std::iter::repeat(5).take(5);
let bump = Bump::new();

let v = Vec::from_iter_in(five_fives, &bump);

assert_eq!(v, [5, 5, 5, 5, 5]);

Implementations on Foreign Types§

source§

impl<T, E, V: FromIteratorIn<T>> FromIteratorIn<Result<T, E>> for Result<V, E>

source§

fn from_iter_in<I>(iter: I, alloc: Self::Alloc) -> Selfwhere I: IntoIterator<Item = Result<T, E>>,

Takes each element in the Iterator: if it is an Err, no further elements are taken, and the Err is returned. Should no Err occur, a container with the values of each Result is returned.

Here is an example which increments every integer in a vector, checking for overflow:

let bump = Bump::new();

let v = vec![1, 2, u32::MAX];
let res: Result<Vec<u32>, &'static str> = v.iter().take(2).map(|x: &u32|
    x.checked_add(1).ok_or("Overflow!")
).collect_in(&bump);
assert_eq!(res, Ok(bumpalo::vec![in &bump; 2, 3]));

let res: Result<Vec<u32>, &'static str> = v.iter().map(|x: &u32|
    x.checked_add(1).ok_or("Overflow!")
).collect_in(&bump);
assert_eq!(res, Err("Overflow!"));
§

type Alloc = <V as FromIteratorIn<T>>::Alloc

source§

impl<T, V: FromIteratorIn<T>> FromIteratorIn<Option<T>> for Option<V>

§

type Alloc = <V as FromIteratorIn<T>>::Alloc

source§

fn from_iter_in<I>(iter: I, alloc: Self::Alloc) -> Selfwhere I: IntoIterator<Item = Option<T>>,

Implementors§

source§

impl<'bump> FromIteratorIn<char> for String<'bump>

§

type Alloc = &'bump Bump

source§

impl<'bump, T> FromIteratorIn<T> for Box<'bump, [T]>

§

type Alloc = &'bump Bump

source§

impl<'bump, T> FromIteratorIn<T> for Vec<'bump, T>

§

type Alloc = &'bump Bump