-
-
Save pythonesque/df8c0c9b14cf84f2c1ce 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
use std::ffi::OsStr; | |
use std::process::Command; | |
use std::borrow::Cow; | |
use std::convert::Into; | |
pub fn exec_slurp<'a>(cmd: &'a str, args: &[&OsStr]) -> Cow<'a, str> { | |
println!("exec_slurp({}, {:?})", cmd, args); | |
Command::new(cmd) | |
.args(args) | |
.output() | |
.ok() | |
.and_then(|x| String::from_utf8(x.stdout).ok() ) | |
.map(Into::into) | |
.unwrap_or(Cow::Borrowed("")) | |
} | |
pub fn exec_slurp_string(cmd: &str, args: &[&OsStr]) -> String { | |
println!("exec_slurp({}, {:?})", cmd, args); | |
Command::new(cmd) | |
.args(args) | |
.output() | |
.ok() | |
.and_then(|x| String::from_utf8(x.stdout).ok() ) | |
.unwrap_or(String::new()) | |
} | |
fn main() { | |
} |
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
use std::path::Path; | |
use std::ffi::OsStr; | |
fn foo<'a>(strings: &[&'a AsRef<Path>]) -> Vec<&'a Path> { | |
strings.into_iter().map(AsRef::as_ref).collect() | |
} | |
fn main() { | |
foo(&[&"biz".to_string(), &Path::new("foo/bar/baz"), &OsStr::new("zab"), &"baz"]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment