pub trait IteratorExt: Iterator + Sealed {
    // Provided methods
    fn try_collect<B>(self) -> Result<B, Error>
       where Self: Sized,
             B: TryFromIteratorIn<Self::Item, Global> { ... }
    fn try_collect_in<B, A>(self, alloc: A) -> Result<B, Error>
       where A: Allocator,
             Self: Sized,
             B: TryFromIteratorIn<Self::Item, A> { ... }
    fn try_join<J, S>(self, sep: S) -> Result<J, Error>
       where Self: Sized,
             J: TryJoin<S, Self::Item, Global> { ... }
    fn try_join_in<J, S, A>(self, sep: S, alloc: A) -> Result<J, Error>
       where A: Allocator,
             Self: Sized,
             J: TryJoin<S, Self::Item, A> { ... }
    fn try_cloned<'a, T>(self) -> TryCloned<Self> 
       where T: 'a + TryClone,
             Self: Sized + Iterator<Item = &'a T> { ... }
}
Expand description

Iterator extension trait.

Provided Methods§

source

fn try_collect<B>(self) -> Result<B, Error>
where Self: Sized, B: TryFromIteratorIn<Self::Item, Global>,

Transforms an iterator into a collection using fallible allocations.

source

fn try_collect_in<B, A>(self, alloc: A) -> Result<B, Error>
where A: Allocator, Self: Sized, B: TryFromIteratorIn<Self::Item, A>,

Transforms an iterator into a collection using fallible allocations.

source

fn try_join<J, S>(self, sep: S) -> Result<J, Error>
where Self: Sized, J: TryJoin<S, Self::Item, Global>,

Try to join the given value.

§Examples
use rune::alloc::String;
use rune::alloc::prelude::*;

let values = ["foo", "bar"];
let string: String = values.into_iter().try_join("/")?;
assert_eq!(string, "foo/bar");

let values = ["foo", "bar"];
let string: String = values.into_iter().try_join('/')?;
assert_eq!(string, "foo/bar");
source

fn try_join_in<J, S, A>(self, sep: S, alloc: A) -> Result<J, Error>
where A: Allocator, Self: Sized, J: TryJoin<S, Self::Item, A>,

Try to join the given value.

source

fn try_cloned<'a, T>(self) -> TryCloned<Self>
where T: 'a + TryClone, Self: Sized + Iterator<Item = &'a T>,

Creates an iterator which try_clones all of its elements.

This is useful when you have an iterator over &T, but you need an iterator over T.

There is no guarantee whatsoever about the try_clone method actually being called or optimized away. So code should not depend on either.

§Examples

Basic usage:

use rune::alloc::{try_vec, Vec};
use rune::alloc::prelude::*;

let a = [1, 2, 3];

let v_cloned: Vec<_> = a.iter().try_cloned().try_collect::<Result<_, _>>()??;

// cloned is the same as .map(|&x| x), for integers
let v_map: Vec<_> = a.iter().map(|&x| x).try_collect()?;

assert_eq!(v_cloned, [1, 2, 3]);
assert_eq!(v_map, [1, 2, 3]);

Implementors§

source§

impl<I> IteratorExt for I
where I: Iterator,