Skip to main content

MultiErrors

Struct MultiErrors 

Source
pub struct MultiErrors<E = Error> { /* private fields */ }
Expand description

A collection of errors that enables continuing work while collecting failures.

This type implements the “error parameter” pattern: instead of short-circuiting on the first error, processing continues and errors are accumulated. The caller can inspect the collection afterward to determine whether all operations succeeded.

§Ergonomic Result handling

collect_result lets you process a Result<T, E> while keeping the happy path dominant:

use vtcode_commons::MultiErrors;
let mut errors: MultiErrors<String> = MultiErrors::new();
let value: Option<i32> = errors.collect_result("42".parse::<i32>().map_err(|e| e.to_string()));
assert_eq!(value, Some(42));

§Composing with traditional error handling

Use ok or to_anyhow to convert back into a traditional Result.

Implementations§

Source§

impl<E> MultiErrors<E>

Source

pub fn new() -> Self

Create an empty error collection.

Source

pub fn push(&mut self, error: E)

Add a single error to the collection.

Source

pub fn extend(&mut self, iter: impl IntoIterator<Item = E>)

Extend the collection with multiple errors.

Source

pub fn is_empty(&self) -> bool

Returns true if no errors have been collected.

Source

pub fn len(&self) -> usize

Returns the number of collected errors.

Source

pub fn into_inner(self) -> Vec<E>

Consume the collector and return the underlying error vector.

Source

pub fn as_slice(&self) -> &[E]

Returns a slice of all collected errors.

Source

pub fn iter(&self) -> Iter<'_, E>

Returns an iterator over the collected errors.

Source

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

Convert into Result<()> — succeeds if no errors were collected.

Source

pub fn clear(&mut self)

Remove all errors from the collection.

Source

pub fn collect_result<T, F>(&mut self, result: Result<T, F>) -> Option<T>
where F: Into<E>,

Process a Result, returning the success value or collecting the error.

This is the key ergonomic method — it keeps the happy path as the primary flow while silently collecting errors for later inspection.

Source

pub fn to_anyhow(&self) -> Error
where E: Display,

Convert into an anyhow::Error for use with traditional error handling.

Trait Implementations§

Source§

impl<E: Clone> Clone for MultiErrors<E>

Source§

fn clone(&self) -> MultiErrors<E>

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<E: Debug> Debug for MultiErrors<E>

Source§

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

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

impl<E> Default for MultiErrors<E>

Source§

fn default() -> Self

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

impl<'de, E: Deserialize<'de>> Deserialize<'de> for MultiErrors<E>

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

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

impl<E: Display> Display for MultiErrors<E>

Source§

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

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

impl<E: Error + 'static> Error for MultiErrors<E>

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<E> From<Vec<E>> for MultiErrors<E>

Source§

fn from(errors: Vec<E>) -> Self

Converts to this type from the input type.
Source§

impl<E> IntoIterator for MultiErrors<E>

Source§

type Item = E

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<E>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<E: Serialize> Serialize for MultiErrors<E>

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<E> Freeze for MultiErrors<E>

§

impl<E> RefUnwindSafe for MultiErrors<E>
where E: RefUnwindSafe,

§

impl<E> Send for MultiErrors<E>
where E: Send,

§

impl<E> Sync for MultiErrors<E>
where E: Sync,

§

impl<E> Unpin for MultiErrors<E>
where E: Unpin,

§

impl<E> UnsafeUnpin for MultiErrors<E>

§

impl<E> UnwindSafe for MultiErrors<E>
where E: UnwindSafe,

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> 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<I, C> CompactStringExt for C
where I: AsRef<str>, C: IntoIterator<Item = I>,

Source§

fn concat_compact(self) -> CompactString

Concatenates all the items of a collection into a CompactString Read more
Source§

fn join_compact<S>(self, separator: S) -> CompactString
where S: AsRef<str>,

Joins all the items of a collection, placing a separator between them, forming a CompactString Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToCompactString for T
where T: Display,

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

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more