resiter_dpc_tmp/
errors.rs

1//
2// This Source Code Form is subject to the terms of the Mozilla Public
3// License, v. 2.0. If a copy of the MPL was not distributed with this
4// file, You can obtain one at http://mozilla.org/MPL/2.0/.
5//
6
7use std::iter::*;
8
9use util::*;
10
11pub use util::Process as Errors;
12// for backward compatibility with previous implementation
13
14/// Extension trait for `Iterator<Item = Result<T, E>>` to get all `E`s
15pub trait GetErrors<T, E> : Sized {
16    fn errors(self) -> FilterMap<Self, fn(Result<T,E>) -> Option<E>>;
17}
18
19impl<T, E, I> GetErrors<T, E> for I
20    where I: Iterator<Item = Result<T, E>> + Sized
21{
22    fn errors(self) -> FilterMap<Self, fn(Result<T,E>) -> Option<E>> {
23        self.filter_map(GetErr::get_err)
24    }
25}
26
27#[test]
28fn test_compile() {
29    use std::str::FromStr;
30
31    let _ : Result<_, ::std::num::ParseIntError> = ["1", "2", "3", "4", "5"]
32        .into_iter()
33        .map(|e| usize::from_str(e))
34        .errors()
35        .process(|e| { println!("Error: {:?}", e); Ok(()) });
36}
37