pub struct Env { /* private fields */ }Expand description
Implementations§
Source§impl Env
impl Env
Sourcepub fn value(&self) -> Result<OsString, Error>
pub fn value(&self) -> Result<OsString, Error>
Read the value of the current variable.
§Errors
Returns Error::Missing if the current variable is missing.
§Examples
enum Color {
Orange,
Blue,
}
impl Tenvy for Color {
fn from_env(env: &Env) -> Result<Self, Error> {
#[derive(Debug, thiserror::Error)]
#[error("expected `orange` or `blue`")]
struct InvalidColor;
match env.value()?.to_str() {
Some("orange") => Ok(Self::Orange),
Some("blue") => Ok(Self::Blue),
_ => Err(Error::invalid_value(env, InvalidColor)),
}
}
}Trait Implementations§
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