confroid 0.0.1

The n+1-st config reader for your environment-based configs.
Documentation
//! Error types produced while reading configuration from the environment.

/// The error type returned by [`from_env`](crate::from_env) and the
/// [`FromEnv`](crate::FromEnv) trait.
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[non_exhaustive]
pub enum ConfroidError {
    /// A required environment variable was not set.
    ///
    /// For a scalar field this means the exact variable is missing. For a
    /// collection (`Vec`/`HashMap`) it means none of its indexed/keyed
    /// variables were present and the field has no default.
    #[error("environment variable `{var_name}` (field `{field}`) is not set")]
    EnvVarNotFound {
        /// The environment variable name, e.g. `HTTP__PORT`.
        var_name: String,
        /// The dotted field path, e.g. `http.port`.
        field: String,
    },

    /// An environment variable was set but its value could not be parsed into
    /// the target type.
    #[error(
        "environment variable `{var_name}` (field `{field}`) has invalid value `{value}`: {parser_error}"
    )]
    EnvVarInvalid {
        /// The environment variable name, e.g. `HTTP__PORT`.
        var_name: String,
        /// The dotted field path, e.g. `http.port`.
        field: String,
        /// The raw value that failed to parse.
        value: String,
        /// The underlying parser error, rendered via `Display`.
        parser_error: String,
    },

    /// A `Vec` field had non-contiguous indices (e.g. `FOO__0` and `FOO__2`
    /// with no `FOO__1`).
    #[error(
        "vector `{field}` (var `{var_name}`) is missing index {missing}; indices must be contiguous starting at 0"
    )]
    VecIndexGap {
        /// The environment variable prefix, e.g. `NAMES`.
        var_name: String,
        /// The dotted field path, e.g. `names`.
        field: String,
        /// The first missing index.
        missing: usize,
    },
}

/// Convenient result alias.
pub type Result<T> = core::result::Result<T, ConfroidError>;