dotenv-typed 11.2.0

Zero-dependency .env file parser, variable interpolation engine, typed environment configuration loader, and secret-redacting Debug wrapper.
Documentation
use super::*;

/// Constructors and explicit accessors for [`SecretString`].
impl SecretString {
    /// Wraps a secret string.
    ///
    /// # Arguments
    ///
    /// - `S` - Sensitive string value.
    ///
    /// # Returns
    ///
    /// - `Self` - Redacting secret wrapper.
    pub fn new<S>(value: S) -> Self
    where
        S: Into<String>,
    {
        Self {
            inner: value.into(),
        }
    }

    /// Explicitly exposes the underlying secret string slice.
    ///
    /// # Returns
    ///
    /// - `&str` - Secret string value.
    #[inline(always)]
    pub fn expose(&self) -> &str {
        let Self { inner } = self;
        inner.as_str()
    }

    /// Returns the byte length of the underlying secret.
    ///
    /// # Returns
    ///
    /// - `usize` - Secret byte length.
    #[inline(always)]
    pub fn len(&self) -> usize {
        let Self { inner } = self;
        inner.len()
    }

    /// Returns whether the secret is empty.
    ///
    /// # Returns
    ///
    /// - `bool` - `true` when empty.
    #[inline(always)]
    pub fn is_empty(&self) -> bool {
        self.len() == 0
    }
}

/// Redacts [`SecretString`] in `Debug` output.
impl fmt::Debug for SecretString {
    /// Writes `[REDACTED]` instead of the secret bytes.
    ///
    /// # Arguments
    ///
    /// - `&mut fmt::Formatter<'_>` - Destination formatter.
    ///
    /// # Returns
    ///
    /// - `fmt::Result` - Formatting outcome.
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str(REDACTED_MARKER)
    }
}

/// Redacts [`SecretString`] in `Display` output.
impl fmt::Display for SecretString {
    /// Writes `[REDACTED]` instead of the secret bytes.
    ///
    /// # Arguments
    ///
    /// - `&mut fmt::Formatter<'_>` - Destination formatter.
    ///
    /// # Returns
    ///
    /// - `fmt::Result` - Formatting outcome.
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str(REDACTED_MARKER)
    }
}