resiter_dpc_tmp/
oks.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 Oks;
12// for backward compatibility with previous implementation
13
14
15/// Extension trait for `Iterator<Item = Result<T, E>>` to get all `T`s
16pub trait GetOks<T, E> : Sized {
17    fn oks(self) -> FilterMap<Self, fn(Result<T,E>) -> Option<T>>;
18}
19
20impl<T, E, I> GetOks<T, E> for I
21    where I: Iterator<Item = Result<T, E>> + Sized
22{
23    fn oks(self) -> FilterMap<Self, fn(Result<T,E>) -> Option<T>> {
24        self.filter_map(GetOk::get_ok)
25    }
26}
27
28
29#[test]
30fn test_compile() {
31    use std::str::FromStr;
32
33    let _ : Result<_, ::std::num::ParseIntError> = ["1", "2", "3", "4", "5"]
34        .into_iter()
35        .map(|e| usize::from_str(e))
36        .oks()
37        .process(|o| { println!("Ok: {:?}", o); Ok(()) });
38}