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 Self: Sized + Iterator<Item = &'a T>,
T: 'a + TryClone { ... }
}
Expand description
Iterator extension trait.
Provided Methods§
Sourcefn try_collect<B>(self) -> Result<B, Error>
fn try_collect<B>(self) -> Result<B, Error>
Transforms an iterator into a collection using fallible allocations.
Sourcefn try_collect_in<B, A>(self, alloc: A) -> Result<B, Error>
fn try_collect_in<B, A>(self, alloc: A) -> Result<B, Error>
Transforms an iterator into a collection using fallible allocations.
Sourcefn try_join<J, S>(self, sep: S) -> Result<J, Error>
fn try_join<J, S>(self, sep: S) -> Result<J, Error>
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");
Sourcefn try_join_in<J, S, A>(self, sep: S, alloc: A) -> Result<J, Error>
fn try_join_in<J, S, A>(self, sep: S, alloc: A) -> Result<J, Error>
Try to join the given value.
Sourcefn try_cloned<'a, T>(self) -> TryCloned<Self> ⓘ
fn try_cloned<'a, T>(self) -> TryCloned<Self> ⓘ
Creates an iterator which try_clone
s 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]);