pub struct EnvUtils;
Expand description
Utility functions related to environment variables.
Implementations§
Source§impl EnvUtils
impl EnvUtils
Sourcepub fn get_property_or_default<K: AsRef<OsStr>>(
key: K,
default: impl Into<String>,
) -> String
pub fn get_property_or_default<K: AsRef<OsStr>>( key: K, default: impl Into<String>, ) -> String
Retrieves the value of the specified environment variable or returns a default value if the variable is not set.
§Arguments
key
- The name of the environment variable to retrieve.default
- The default value to return if the environment variable is not set.
§Returns
A String
containing the value of the environment variable, or the default value.
Sourcepub fn get_property_as_i32<K: AsRef<OsStr>>(key: K, default: i32) -> i32
pub fn get_property_as_i32<K: AsRef<OsStr>>(key: K, default: i32) -> i32
Retrieves the value of the specified environment variable as an i32
, or returns a default
value if the variable is not set or cannot be parsed.
§Arguments
key
- The name of the environment variable to retrieve.default
- The default value to return if the environment variable is not set or cannot be parsed.
§Returns
An i32
containing the value of the environment variable, or the default value.
Sourcepub fn get_property_as_bool<K: AsRef<OsStr>>(key: K, default: bool) -> bool
pub fn get_property_as_bool<K: AsRef<OsStr>>(key: K, default: bool) -> bool
Retrieves the value of the specified environment variable as a bool
, or returns a default
value if the variable is not set or cannot be parsed.
§Arguments
key
- The name of the environment variable to retrieve.default
- The default value to return if the environment variable is not set or cannot be parsed.
§Returns
A bool
containing the value of the environment variable, or the default value.
§Notes
The function considers the following values as true
: "true"
, "1"
.
The function considers the following values as false
: "false"
, "0"
.
Sourcepub fn put_property<K: AsRef<OsStr>, V: AsRef<OsStr>>(key: K, value: V)
pub fn put_property<K: AsRef<OsStr>, V: AsRef<OsStr>>(key: K, value: V)
Sets the value of the specified environment variable.
§Arguments
key
- The name of the environment variable to set.value
- The value to set the environment variable to.
§Safety
This function uses unsafe
because it modifies the environment variables,
which can have side effects on the entire process.
Sourcepub fn get_rocketmq_home() -> String
pub fn get_rocketmq_home() -> String
Gets the value of the ROCKETMQ_HOME environment variable.
If ROCKETMQ_HOME is not set, it defaults to the current directory and sets ROCKETMQ_HOME accordingly.
§Returns
The value of the ROCKETMQ_HOME environment variable as a String
.