1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! Inspection and manipulation of the process's environment.
//!
//! This module contains functions to inspect various aspects such as
//! environment variables, process arguments, the current directory, and various
//! other important directories.
//!
//! There are several functions and structs in this module that have a
//! counterpart ending in `os`. Those ending in `os` will return an [`OsString`](std::ffi::OsString)
//! and those without will return a [`String`].
//!
//! This crate provides <code>[mod@std::env]::{[set_var], [remove_var]}</code> safely.
pub use *;
use OsStr;
/// Whether the operating system has a thread-safe environment. This allows bypassing the check for if the process is multi-threaded.
const SAFE: bool = matches!;
/// Sets the environment variable `key` to the value `value` for the currently running
/// process. (safely!)
///
/// # Safety
///
/// This function is safe to call.
/// This function returns [`None`] if it would be unsafe to call this function.
///
/// See also [`std::env::set_var`].
///
/// # Panics
///
/// This function may panic if `key` is empty, contains an ASCII equals sign `'='`
/// or the NUL character `'\0'`, or when `value` contains the NUL character.
///
/// # Examples
///
/// ```
/// let key = "KEY";
/// env::set_var(key, "VALUE").expect("ok");
/// assert_eq!(env::var(key), Ok("VALUE".to_string()));
/// ```
/// Removes an environment variable from the environment of the currently running process. (safely!)
///
/// # Safety
///
/// This function is safe to call.
/// This function returns [`None`] if it would be unsafe to call this function.
///
/// See also [`std::env::remove_var`].
///
/// # Panics
///
/// This function may panic if `key` is empty, contains an ASCII equals sign
/// `'='` or the NUL character `'\0'`, or when the value contains the NUL
/// character.
///
/// # Examples
///
/// ```
/// let key = "KEY";
/// env::set_var(key, "VALUE").expect("ok");
/// assert_eq!(env::var(key), Ok("VALUE".to_string()));
/// env::remove_var(key).expect("ok");
/// assert!(env::var(key).is_err());
/// ```