std::env::join_paths

Function std::env::join_paths

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

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

Returns an OsString on success.

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

Examples

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).unwrap();
    env::set_var("PATH", &new_path);
}

© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/env/fn.join_paths.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部