use std::fmt;
use std::sync::Arc;
#[derive(Clone)]
pub(crate) struct Env(Arc<Read>);
type Read = dyn Fn(&str) -> Option<String> + Send + Sync;
impl Env {
pub(crate) fn new(read: impl Fn(&str) -> Option<String> + Send + Sync + 'static) -> Self {
Self(Arc::new(read))
}
pub(crate) fn process() -> Self {
Self::new(|name| std::env::var(name).ok())
}
pub(crate) fn get(&self, name: &str) -> Option<String> {
self.raw(name).filter(|value| !value.is_empty())
}
pub(crate) fn raw(&self, name: &str) -> Option<String> {
(self.0)(name)
}
}
impl fmt::Debug for Env {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("Env")
}
}