Created
May 9, 2018 20:41
-
-
Save mexus/23db9d8f4de9468703ece2101a7ed3df to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate result; | |
use std::fmt::Debug; | |
use std::io::{ErrorKind, Result}; | |
use std::path::Path; | |
use result::prelude::*; | |
fn check_path<P: AsRef<Path> + Debug>(path: P) -> Result<Option<P>> { | |
println!("Processing path {:?}", path); | |
Err(ErrorKind::NotFound.into()) | |
} | |
fn select_path<I, P>(paths: I) -> Result<Option<P>> | |
where | |
I: IntoIterator<Item = P>, | |
P: AsRef<Path> + Debug, | |
{ | |
paths | |
.into_iter() | |
.map(check_path) | |
.filter_map(ResultOptionExt::invert) | |
.next_invert() | |
} | |
fn main() { | |
select_path(&["/var", "/var/lib/"]) | |
.expect("...") | |
.expect("..."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment