Skip to main content

BindError

Struct BindError 

Source
pub struct BindError { /* private fields */ }
Expand description

A binding error that does not retain raw parameter values.

§Examples

use qubit_validator::{BindError, BindErrorKind};

let error = BindError::new(BindErrorKind::MissingParameter).with_parameter("minimum");
assert_eq!(error.parameter(), Some("minimum"));
assert!(!error.to_string().contains("secret value"));

Implementations§

Source§

impl BindError

Source

pub fn new(kind: BindErrorKind) -> Self

Creates a binding error for the supplied failure category.

§Parameters
  • kind: Stable category describing why binding failed.
§Returns

A new error without an associated rule, parameter, or dependency.

Source

pub const fn kind(&self) -> BindErrorKind

Returns the error kind.

§Returns

The stable category describing the binding failure.

Examples found in repository?
examples/local_registry.rs (line 146)
139fn assert_parameters_are_consumed_once() -> Result<(), BindError> {
140    let args = [NamedValidationArgument::new("limit", ValidationArgument::Unsigned(10))];
141    let mut reader = ArgumentReader::new(&args)?;
142    assert_eq!(reader.required_u32("limit")?, 10);
143    let error = reader
144        .required_u32("limit")
145        .expect_err("a parameter cannot be read twice");
146    assert_eq!(error.kind(), BindErrorKind::ParameterAlreadyConsumed);
147    Ok(())
148}
Source

pub const fn rule_id(&self) -> Option<ValidatorId>

Returns the resolved rule identifier attached to this error, if any.

A registry lookup that fails with MissingRule has no resolved ValidatorId, so this returns None. The caller retains the requested ID text when it needs to report which lookup failed.

§Returns

The resolved identifier for a selected rule, or None when no rule was selected.

Source

pub fn parameter(&self) -> Option<&str>

Returns the associated parameter name, if any.

The error never retains the corresponding raw parameter value.

§Returns

Returns Some when a parameter has been attached, or None otherwise.

Source

pub fn dependency(&self) -> Option<&str>

Returns the associated dependency name, if any.

The error never retains the corresponding raw dependency value.

§Returns

Returns Some when a dependency has been attached, or None otherwise.

Source

pub const fn with_rule(self, rule_id: ValidatorId) -> Self

Associates the resolved rule identifier with this error.

§Parameters
  • rule_id: Identifier of the rule whose binding failed.
§Returns

This error with the identifier attached.

Source

pub fn with_parameter(self, parameter: impl Into<String>) -> Self

Associates a parameter name with this error without retaining its value.

§Parameters
  • parameter: Name of the parameter involved in the failure.
§Returns

This error with the parameter name attached.

Source

pub fn with_dependency(self, dependency: impl Into<String>) -> Self

Associates a dependency name with this error without retaining its value.

§Parameters
  • dependency: Name of the dependency involved in the failure.
§Returns

This error with the dependency name attached.

Trait Implementations§

Source§

impl Debug for BindError

Source§

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

Formats structural metadata without exposing raw parameter values.

Source§

impl Display for BindError

Source§

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

Formats a stable summary without exposing raw parameter values.

Source§

impl Error for BindError

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

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.