pub trait UnsafeNext<T, E: Debug>: Iterator<Item = Result<T, E>> {
    // Provided method
    fn next_unwrap(&mut self) -> T { ... }
}
Expand description

Forcibly extract an item out of an iterator of Results.

If you have an iterator that holds Result items, it quickly becomes annoying to constantly unwrap. This trait provides the method next_unwrap to quickly extract the inner item.

Provided Methods§

source

fn next_unwrap(&mut self) -> T

§Example
struct IterVec<T, E>(Vec<Result<T, E>>);
impl<T, E: std::fmt::Debug> Iterator for IterVec<T, E> {
}
impl<T, E: std::fmt::Debug> UnsafeNext<T, E> for IterVec<T, E> {}
 
let mut iter: IterVec<i32, ()> = IterVec(vec![Ok(1)]);
assert_eq!(1, iter.next_unwrap());
iter.next_unwrap(); // panic!
§Panics

Panics if the next element is either None or an Err.

Implementors§