Trait FromIteratorIn

Source
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) -> Self
where 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]);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

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) -> Self
where 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!"));
Source§

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

Source§

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

Source§

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

Source§

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

Implementors§

Source§

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

Source§

type Alloc = &'bump Bump

Source§

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

Source§

type Alloc = &'bump Bump