Skip to content

Instantly share code, notes, and snippets.

Forked from barafael/
Last active March 23, 2017 18:26
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save durka/d4045a62acb3e359226098102da56f33 to your computer and use it in GitHub Desktop.
Confused about error handling
use std::process::Command;
fn main() {
println!("{}", git_name().unwrap_or("".to_string()));
pub fn git_name() -> Option<String> {
if let Ok(output) = Command::new("git")
if output.status.success() {
let s = String::from_utf8_lossy(&output.stdout);
print!("git config {}", s);
} else {
let s = String::from_utf8_lossy(&output.stderr);
print!("git config failed! {}", s);
} else {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment