I have this code
fn get_last_commit () -> String { Command::new("git") .arg("rev-parse") .arg("HEAD") .output() .map(|output| { String::from_utf8(output.stdout).ok().expect("error reading into string") }) .ok().expect("error invoking git rev-parse") } I'd like to be able to cut the ok().expect(..) a bit down so that I ideally have something like that:
fn get_last_commit () -> String { Command::new("git") .arg("rev-parse") .arg("HEAD") .output() .and_then(|output| { String::from_utf8(output.stdout) }) .ok().expect("error invoking git rev-parse") } However, that doesn't work because the errors don't line up leaving me with:
mismatched types: expected `core::result::Result<_, std::io::error::Error>`, found `core::result::Result<collections::string::String, collections::string::FromUtf8Error>` (expected struct `std::io::error::Error`, found struct `collections::string::FromUtf8Error`) I know the error handling changed quite a bit within the last month and I have the feeling there should be away to get them aligned without too much hassle. I seem unable to figure it out though.