A simple library for temporarily changing the current working directory.
Add this to your Cargo.toml:
[dependencies]
pushd = "0.0.1"use anyhow::Resultuse std::path::PathBuf;use pushd::Pushd;fnmain() -> Result<()>{write_in_etc()?;// Current working directory is whatever it was before the call to// `write_in_etc`.}fnwrite_in_etc() -> Result<()>{let path = PathBuf::new("/etc");let _pd = Pushd::new(path)?;// Current working directory is now /etc//// Do something in /etc.}