pub struct Env { /* private fields */ }Expand description
Safe wrapper around std::env::vars_os, which is safe to access on Windows: some of its
environmental variables are case-insensitive.
Implementations§
Source§impl Env
impl Env
Sourcepub fn new_from(env: HashMap<OsString, OsString>) -> Self
pub fn new_from(env: HashMap<OsString, OsString>) -> Self
Create new Env using env as existing environmental variables.
Sourcepub fn reload_from(&mut self, env: HashMap<OsString, OsString>)
pub fn reload_from(&mut self, env: HashMap<OsString, OsString>)
Reload environmental variables from env.
Sourcepub fn reload(&mut self)
pub fn reload(&mut self)
Reload environmental variables from std::env::vars_os.
Sourcepub fn get_os(&self, key: impl AsRef<OsStr>) -> Option<&OsStr>
pub fn get_os(&self, key: impl AsRef<OsStr>) -> Option<&OsStr>
Get environmental variable pointed by key.
§Arguments
key- key for environmental variable. Must implementAsRef<OsStr>.
§Returns
Option<&OsStr>. None variant indicates missing key, Some: existing key.
§Examples
use rustvil::os::env::Env;
let env = Env::new();
println!("$FOO = {:?}", env.get_os("FOO"));Sourcepub fn get(&self, key: impl AsRef<OsStr>) -> Result<&str, EnvStrError>
pub fn get(&self, key: impl AsRef<OsStr>) -> Result<&str, EnvStrError>
Get environmental variable pointed by key and convert it to UTF-8.
§Arguments
key- key for environmental variable. Must implementAsRef<Str>.
§Returns
Result<&str, EnvStrError>. Ok variant indicates existing UTF-8 variable, Err
indicates some kind of error. See EnvStrError for
details.
§Examples
use rustvil::os::env::Env;
let env = Env::new();
let _path = env.get("PATH")?;Trait Implementations§
impl Eq for Env
impl StructuralPartialEq for Env
Auto Trait Implementations§
impl Freeze for Env
impl RefUnwindSafe for Env
impl Send for Env
impl Sync for Env
impl Unpin for Env
impl UnwindSafe for Env
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more