pub fn set_current_dir<P: AsRef<Path>>(path: P) -> Result<CurrentDir, Error>Expand description
Memorize the current path and switch to the given path. Once the datastructure is dropped, switch back to the original path automatically.
{
let _tmp_current_dir = tmp_env::set_current_dir("src").expect("should set the new current_dir");
let current_dir = std::env::current_dir().expect("cannot get current dir from std env");
assert!(current_dir.ends_with("src"));
}
let current_dir = std::env::current_dir().expect("cannot get current dir from std env");
assert!(!current_dir.ends_with("src"));
// Because guard is dropped
tmp_env::set_current_dir("target").expect("should set the new current_dir");
assert!(!current_dir.ends_with("target"));