Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
envz
A small Rust library for persistently reading and modifying Windows environment variables through the registry.
Unlike std::env::set_var, which only changes the environment of the
current process, envz writes directly to the Environment key under
HKEY_CURRENT_USER (or any registry key you provide), so the changes
survive process exit and are picked up by newly started programs — the
same effect as editing environment variables through the Windows GUI.
Platform: Windows only. This crate depends on the
windowsandwindows-registrycrates and will not build on other platforms.
Features
- Get, set, and remove persistent user environment variables.
- Support for both regular (
REG_SZ) and expandable (REG_EXPAND_SZ) string values, so values containing references like%JAVA_HOME%are stored correctly. - Convenient helpers for managing the
Pathvariable:- read it as a
Vec<PathBuf> - append (
push) or prepend (insert) entries, skipping case-insensitive duplicates - remove entries
- read it as a
- Works against
HKEY_CURRENT_USER\Environmentby default, or against any registry key you supply (e.g. for machine-wide/system environment variables, or for testing). - A
varmodule with free functions for quick, one-off changes without having to construct anEnvironmentyourself. - Errors are unified into a single
envz::Error/envz::Resulttype.
Installation
Add envz to your Cargo.toml:
[]
= "0.1"
Or, to track the repository directly:
[]
= { = "https://github.com/Delphier/envz" }
Usage
Reading and writing a variable
use Environment;
Quick one-off changes with the var module
use var;
Managing Path
use path;
Using a custom registry key
Environment::create lets you target a different key, for example the
system-wide environment variables (which typically requires
administrator privileges) or a key used in tests:
use Environment;
use LOCAL_MACHINE;
Notes on change propagation
envz writes directly to the registry, exactly like the Windows
Environment Variables dialog does. Already-running processes (including
the current process, and shells such as cmd.exe or PowerShell that
were already open) will not see the new values until they are
restarted, or until the system broadcasts a WM_SETTINGCHANGE message
(which the Windows GUI does automatically, but this crate does not do
for you).
License
Licensed under either of
at your option.