Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
In [ ]:
:timing
:sccache 1
Tips and Traps¶
- Notice
std::env::current_dir
gets the directory path from where you run the Rust application. It might be different from the path of the Rust executable.
In [2]:
use std::env;
In [3]:
std::env::current_dir()
Out[3]:
In [5]:
std::env::current_exe()
Out[5]:
In [7]:
std::env::set_current_dir("/workdir")
Out[7]:
In [8]:
std::env::current_dir()
Out[8]:
In [17]:
for var in std::env::vars() {
println!("{:?}", var);
}
Out[17]:
In [14]:
std::env::var("PATH")
Out[14]:
In [26]:
std::env::set_var("NIMA", "1000");
In [27]:
std::env::var("NIMA")
Out[27]:
In [28]:
std::env::remove_var("NIMA")
Out[28]:
In [25]:
let paths = std::env::var("PATH")?;
for path in std::env::split_paths(&paths) {
println!("{:?}", path);
}
Out[25]:
In [12]:
std::env::join_paths(&["/workdir", "/home/dclong"])
Out[12]:
In [29]:
std::env::temp_dir()
Out[29]: