Crate tmp_env

Source
Expand description

tmp_env is a crate which lets you create temporary environment and be automatically restored/cleaned when not needed. For example sometimes you need to change the current directory or set environment variables to launch a process but you don’t need this temporary environment for the rest of your program. Then you will use tmp_env to create environment variable using tmp_env::set_var instead of std::env::set_var to get from tmp_env::set_var a datastructure which will automatically restore the corresponding environmet variable when dropped.

Structs§

CurrentDir
A helper datastructure for ensuring that we switch back to the current folder before the end of the current scope.
CurrentEnv
A helper datastructure for ensuring that we restore the current environment variable before the end of the current scope.
TmpDir
A helper datastructure for ensuring that we delete the tmp dir created before end of the current scope.

Functions§

create_temp_dir
Create a temporary directory in the temporary directory of your operating system
set_current_dir
Memorize the current path and switch to the given path. Once the datastructure is dropped, switch back to the original path automatically.
set_var
Sets the environment variable k to the value v for the currently running process. It returns a datastructure to keep the environment variable set. When dropped the environment variable is restored