Skip to content

Instantly share code, notes, and snippets.

@mexus
Created May 9, 2018 20:41
Show Gist options
  • Save mexus/23db9d8f4de9468703ece2101a7ed3df to your computer and use it in GitHub Desktop.
Save mexus/23db9d8f4de9468703ece2101a7ed3df to your computer and use it in GitHub Desktop.
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