pub trait IteratorExt: Sized + Iterator {
// Provided methods
fn vec<T>(self) -> Vec<T>
where Self: Iterator<Item = T> { ... }
fn dict<K, V>(self) -> HashMap<K, V>
where Self: Iterator<Item = (K, V)>,
K: Hash + Eq { ... }
}
Available on crate feature
std
only.Expand description
Provides a convenience .vec()
and .dict()
adapters to collect an i!(…)
iterator expression into a Vec
and a
HashMap
respectively.
§Example
use ::iter_python::prelude::*;
assert_eq!(
i!(x for x in 0 .. 5).vec(),
v![x for x in 0 .. 5],
);
assert_eq!(
i!((x, x * x) for x in 1 ..= 2).dict(),
{
let mut map = ::std::collections::HashMap::new();
map.insert(1, 1);
map.insert(2, 4);
map
},
);
Provided Methods§
fn vec<T>(self) -> Vec<T>where
Self: Iterator<Item = T>,
fn dict<K, V>(self) -> HashMap<K, V>
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.