macro_rules! try_from_os_str {
($name:ident as $typ:ty) => { ... };
}Expand description
Convert an &OsStr to another more usefull type
There are lots of ways to do that and this will pick the best via
autoref based specialization
e.g. a PathBuf will becreated via From<OsString> not From<String> so non UTF8 paths
will work.
use from_os_str::*;
use std::ffi::OsStr;
use std::path::Path;
let os_str = OsStr::new("123");
let path = try_from_os_str!(os_str as &Path)?;
assert_eq!(path, Path::new("123"));
let str = try_from_os_str!(os_str as &str)?;
assert_eq!(str, "123");
let string = try_from_os_str!(os_str as String)?;
assert_eq!(string, "123".to_string());
let int = try_from_os_str!(os_str as u8)?;
assert_eq!(int, 123);