ErrorTree

Struct ErrorTree 

Source
pub struct ErrorTree {
    pub messages: Vec<String>,
    pub children: HashMap<String, Self>,
}
Expand description

ErrorTree Hierarchical error aggregator used by validation to keep nested context.

Fields§

§messages: Vec<String>

Errors at the current level.

§children: HashMap<String, Self>

Child errors indexed by field/key.

Implementations§

Source§

impl ErrorTree

Source

pub fn new() -> Self

Create an empty error tree with no messages or children.

Source

pub fn collect<I>(iter: I) -> Result<(), Self>
where I: IntoIterator<Item = Result<(), Self>>,

Merge a sequence of Result values, collecting every ErrorTree into one.

Source

pub fn add<M: ToString>(&mut self, message: M)

Add an error message to the current level.

Source

pub fn add_result<M: ToString>(&mut self, error: Result<(), M>)

Push an error message only when the supplied result is Err.

Source

pub fn addf(&mut self, args: Arguments<'_>)

Format and append an error message.

Source

pub fn add_for<K: ToString, M: ToString>(&mut self, key: K, message: M)

Add an error message under a specific child key, creating nodes as needed.

Source

pub fn merge(&mut self, other: Self)

Merge another ErrorTree into this one, combining children recursively.

Source

pub fn is_empty(&self) -> bool

Check if there are any errors.

Source

pub fn flatten_ref(&self) -> Vec<(String, String)>

Flatten the error hierarchy without consuming self.

Source

pub fn result(self) -> Result<(), Self>

Consume self and return Ok(()) if there are no errors, or Err(self) otherwise.

Trait Implementations§

Source§

impl CandidType for ErrorTree

Source§

fn _ty() -> Type

Source§

fn id() -> TypeId

Source§

fn idl_serialize<__S>(&self, __serializer: __S) -> Result<(), __S::Error>
where __S: Serializer,

Source§

fn ty() -> Type

Source§

impl Debug for ErrorTree

Source§

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

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

impl Default for ErrorTree

Source§

fn default() -> ErrorTree

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ErrorTree

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for ErrorTree

Source§

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

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

impl From<&str> for ErrorTree

Source§

fn from(err: &str) -> Self

Converts to this type from the input type.
Source§

impl From<String> for ErrorTree

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for ErrorTree

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for ErrorTree

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for ErrorTree

Source§

impl StructuralPartialEq for ErrorTree

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

Source§

type Output = T

Should always be Self
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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,