#[cfg(any(feature = "number", feature = "bool"))]
pub mod prim;
pub use prim::*;
#[cfg(feature = "vec")]
pub mod vec;
pub use vec::*;
use crate::error::Error;
use std::convert::{Infallible, TryFrom};
/// Wrapper under String type.
///
/// When we read the environment variable, we automatically convert the value
/// to EnvString and then convert it to your expected type.
#[derive(Debug, Default, PartialEq, Eq, Clone)]
pub struct EString(String);
impl EString {
#[inline]
pub fn parse<T: TryFrom<EString>>(self) -> Result<T, Error> {
let orig = self.0.clone();
<T as TryFrom<EString>>::try_from(self).map_err(|_| Error::Parse(orig))
}
impl<T> From<T> for EString
where
T: std::fmt::Display,
{
fn from(val: T) -> Self {
Self(val.to_string())
impl std::ops::Deref for EString {
type Target = String;
fn deref(&self) -> &Self::Target {
&self.0
impl TryFrom<EString> for String {
type Error = Infallible;
fn try_from(s: EString) -> Result<Self, Self::Error> {
Ok(s.0)
impl TryFrom<EString> for &'static str {
Ok(Box::leak(s.0.into_boxed_str()))