Skip to main content

tilo_process_services/
env.rs

1//! The toolkit's debug, capture and benchmark knobs: `TILO_UI_*` variables.
2
3use std::env::VarError;
4use std::ffi::OsString;
5
6/// `std::env::var_os(name)` through the process's environment access.
7#[must_use]
8pub fn var_os(name: &str) -> Option<OsString> {
9    #[cfg(feature = "native")]
10    {
11        crate::native::env_vars::var_os(name)
12    }
13    #[cfg(not(feature = "native"))]
14    {
15        let _ = name;
16        None
17    }
18}
19
20/// `std::env::var(name)` through the process's environment access.
21///
22/// # Errors
23///
24/// As `std::env::var`: [`VarError::NotPresent`] when the variable is unset,
25/// [`VarError::NotUnicode`] when the value is not UTF-8.
26pub fn var(name: &str) -> Result<String, VarError> {
27    match var_os(name) {
28        Some(value) => value.into_string().map_err(VarError::NotUnicode),
29        None => Err(VarError::NotPresent),
30    }
31}