#![warn(missing_docs)]
use std::ops::Deref;
use envmnt::{ExpandOptions, ExpansionType};
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Env(String);
impl Env {
pub fn new(value: &str) -> Self {
value.into()
}
}
impl From<&str> for Env {
fn from(value: &str) -> Self {
let mut options = ExpandOptions::new();
options.expansion_type = match std::env::consts::FAMILY {
"unix" => Some(ExpansionType::Unix),
"windows" => Some(ExpansionType::Windows),
_ => Some(ExpansionType::All)
};
let result = envmnt::expand(value, Some(options));
Env(result)
}
}
impl Deref for Env {
type Target = String;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<T> AsRef<T> for Env
where
T: ?Sized,
<Env as Deref>::Target: AsRef<T>,
{
fn as_ref(&self) -> &T {
self.deref().as_ref()
}
}
impl PartialEq<String> for Env {
fn eq(&self, other: &String) -> bool {
*self.deref() == *other
}
}
impl PartialEq<Env> for String {
fn eq(&self, other: &Env) -> bool {
*self == *other.deref()
}
}
impl PartialEq<str> for Env {
fn eq(&self, other: &str) -> bool {
*self.deref() == *other
}
}
impl PartialEq<Env> for str {
fn eq(&self, other: &Env) -> bool {
*self == *other.deref()
}
}