Skip to main content

BuildError

Enum BuildError 

Source
pub enum BuildError {
    MissingRequired {
        field: &'static str,
    },
    InvalidValue {
        field: &'static str,
        reason: String,
    },
    InvalidRange {
        field: &'static str,
        min: u64,
        max: u64,
    },
    ConflictingOptions {
        option_a: &'static str,
        option_b: &'static str,
    },
    InvalidProbability {
        field: &'static str,
        value: f64,
    },
    InvalidDuration {
        field: &'static str,
        reason: String,
    },
    DependencyMissing {
        feature: &'static str,
        dependency: &'static str,
    },
    Custom {
        message: String,
    },
}
Expand description

Errors that can occur when building a configuration.

BuildError captures validation failures, constraint violations, and configuration errors that can occur during the build() call.

§Error Categories

CategoryDescriptionExample
MissingRequiredRequired field not setname field is None
InvalidValueValue fails validationthreads = 0
InvalidRangeRange constraints violatedmin > max
ConflictingOptionsMutually exclusive optionssync and async both set
InvalidProbabilityProbability not in [0.0, 1.0]0.5..=1.5
InvalidDurationDuration constraint violatedtimeout = 0
DependencyMissingRequired dependency not configuredtls without certificates
CustomDomain-specific validation errorsApplication-specific rules

§Usage

fn build(self) -> BuildResult<Config> {
    // Check required fields
    let name = self.name.ok_or_else(||
        BuildError::missing_required("name")
    )?;

    // Validate values
    if self.threads == 0 {
        return Err(BuildError::invalid_value("threads", "must be >= 1"));
    }

    // Check ranges
    if self.min_connections > self.max_connections {
        return Err(BuildError::invalid_range(
            "connections",
            self.min_connections,
            self.max_connections,
        ));
    }

    Ok(Config { name, threads: self.threads, ... })
}

Variants§

§

MissingRequired

A required field was not set.

§Example

BuildError::MissingRequired { field: "name" }

Fields

§field: &'static str

The name of the missing field.

§

InvalidValue

A field value failed validation.

§Example

BuildError::InvalidValue {
    field: "worker_threads",
    reason: "must be >= 1".to_string(),
}

Fields

§field: &'static str

The field that failed validation.

§reason: String

Why the value is invalid.

§

InvalidRange

A range constraint was violated (min > max).

§Example

BuildError::InvalidRange {
    field: "connections",
    min: 100,
    max: 10,
}

Fields

§field: &'static str

The field or field pair with the range issue.

§min: u64

The minimum value provided.

§max: u64

The maximum value provided.

§

ConflictingOptions

Two options that cannot both be enabled were set.

§Example

BuildError::ConflictingOptions {
    option_a: "single_threaded",
    option_b: "work_stealing",
}

Fields

§option_a: &'static str

The first conflicting option.

§option_b: &'static str

The second conflicting option.

§

InvalidProbability

A probability value was not in [0.0, 1.0].

§Example

BuildError::InvalidProbability {
    field: "cancel_probability",
    value: 1.5,
}

Fields

§field: &'static str

The field with the invalid probability.

§value: f64

The invalid probability value.

§

InvalidDuration

A duration value violated constraints.

§Example

BuildError::InvalidDuration {
    field: "timeout",
    reason: "must be non-zero".to_string(),
}

Fields

§field: &'static str

The field with the invalid duration.

§reason: String

Why the duration is invalid.

§

DependencyMissing

A dependency required by the configuration is missing.

§Example

BuildError::DependencyMissing {
    feature: "tls",
    dependency: "certificate",
}

Fields

§feature: &'static str

The feature that has the missing dependency.

§dependency: &'static str

The name of the missing dependency.

§

Custom

A custom validation error with arbitrary message.

Use this for domain-specific validation that doesn’t fit other variants.

Fields

§message: String

The error message.

Implementations§

Source§

impl BuildError

Source

pub const fn missing_required(field: &'static str) -> Self

Creates a MissingRequired error.

Source

pub fn invalid_value(field: &'static str, reason: impl Into<String>) -> Self

Creates an InvalidValue error.

Source

pub const fn invalid_range(field: &'static str, min: u64, max: u64) -> Self

Creates an InvalidRange error.

Source

pub const fn conflicting_options( option_a: &'static str, option_b: &'static str, ) -> Self

Creates a ConflictingOptions error.

Source

pub const fn invalid_probability(field: &'static str, value: f64) -> Self

Creates an InvalidProbability error.

Source

pub fn invalid_duration(field: &'static str, reason: impl Into<String>) -> Self

Creates an InvalidDuration error.

Source

pub const fn dependency_missing( feature: &'static str, dependency: &'static str, ) -> Self

Creates a DependencyMissing error.

Source

pub fn custom(message: impl Into<String>) -> Self

Creates a Custom error.

Source

pub const fn field(&self) -> Option<&'static str>

Returns the field name associated with this error, if any.

Source

pub const fn is_missing_required(&self) -> bool

Returns true if this is a missing required field error.

Source

pub const fn is_invalid_value(&self) -> bool

Returns true if this is an invalid value error.

Source

pub const fn is_conflicting_options(&self) -> bool

Returns true if this is a conflicting options error.

Trait Implementations§

Source§

impl Clone for BuildError

Source§

fn clone(&self) -> BuildError

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BuildError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for BuildError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for BuildError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl PartialEq for BuildError

Source§

fn eq(&self, other: &BuildError) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for BuildError

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, _span: NoopSpan) -> Self

Instruments this future with a span (no-op when disabled).
Source§

fn in_current_span(self) -> Self

Instruments this future with the current span (no-op when disabled).
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V