pub trait FromIteratorIn<A> {
    type Alloc;

    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§

The allocator type

Required Methods§

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§

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!"));

Implementors§