Function std::env::join_paths [] [src]

pub fn join_paths<I, T>(paths: I) -> Result<OsString, JoinPathsError> where I: IntoIterator<Item=T>, T: AsRef<OsStr>

Joins a collection of Path`Paths appropriately for the`s appropriately for the PATH`PATH` environment variable.

Returns an OsString`OsString` on success.

Returns an Err`Err(containing an error message) if one of the input` (containing an error message) if one of the input Path`Paths contains an invalid character for constructing the`s contains an invalid character for constructing the PATH`PATH` variable (a double quote on Windows or a colon on Unix).

Examples

fn main() { use std::env; use std::path::PathBuf; if let Some(path) = env::var_os("PATH") { let mut paths = env::split_paths(&path).collect::<Vec<_>>(); paths.push(PathBuf::from("/home/xyz/bin")); let new_path = env::join_paths(paths.iter()).unwrap(); env::set_var("PATH", &new_path); } }
use std::env;
use std::path::PathBuf;

if let Some(path) = env::var_os("PATH") {
    let mut paths = env::split_paths(&path).collect::<Vec<_>>();
    paths.push(PathBuf::from("/home/xyz/bin"));
    let new_path = env::join_paths(paths.iter()).unwrap();
    env::set_var("PATH", &new_path);
}