[−][src]Function spirit::utils::absolute_from_os_str
pub fn absolute_from_os_str(path: &OsStr) -> PathBuf
Tries to read an absolute path from the given OS string.
This converts the path to PathBuf. Then it tries to make it absolute and canonical, so changing current directory later on doesn't make it invalid.
The function never fails. However, the substeps (finding current directory to make it absolute and canonization) might fail. In such case, the failing step is skipped.
The motivation is parsing command line arguments using the structopt
crate. Users are used
to passing relative paths to command line (as opposed to configuration files). However, if the
daemon changes the current directory (for example during daemonization), the relative paths now
point somewhere else.
Examples
use std::path::PathBuf; use structopt::StructOpt; #[derive(Debug, StructOpt)] struct MyOpts { #[structopt(short = "p", parse(from_os_str = "spirit::utils::absolute_from_os_str"))] path: PathBuf, }