ErrorStream

Struct ErrorStream 

Source
pub struct ErrorStream<E>(/* private fields */);
Expand description

A non-empty stream of errors.

Logically, this type is unordered, and it is not guaranteed that the errors will be returned in the order they were added. Attach identifying information to your errors if you want to sort them.

This struct is intended to be used with:

  • The CombineErrors trait, which allows you to combine a tuples of results.
  • The CollectAllErrors trait, which allows you to collect errors from an iterator of results.

To create an ErrorStream from a single error, you can use from or into:

use spacetimedb_data_structures::error_stream::ErrorStream;

enum MyError {
    A(u32),
    B
}

let error: ErrorStream<MyError> = MyError::A(1).into();
// or
let error = ErrorStream::from(MyError::A(1));

This does not allocate (unless your error allocates, of course).

Implementations§

Source§

impl<E> ErrorStream<E>

Source

pub fn expect_nonempty<I: IntoIterator<Item = E>>(errors: I) -> Self

Build an error stream from a non-empty collection. If the collection is empty, panic.

Source

pub fn add_extra_errors<T>( result: Result<T, ErrorStream<E>>, extra_errors: impl IntoIterator<Item = E>, ) -> Result<T, ErrorStream<E>>

Add some extra errors to a result.

If there are no errors, the result is not modified. If there are errors, and the result is Err, the errors are added to the stream. If there are errors, and the result is Ok, the Ok value is discarded, and the errors are returned in a stream.

Source

pub fn iter(&self) -> impl Iterator<Item = &E>

Returns an iterator over the errors in the stream.

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut E>

Returns a mutable iterator over the errors in the stream.

Source

pub fn drain(&mut self) -> impl Iterator<Item = E> + '_

Returns an iterator over the errors in the stream, consuming the stream.

Source

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

Push an error onto the stream.

Source

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

Extend the stream with another stream.

Source§

impl<E: Ord + Eq> ErrorStream<E>

Source

pub fn sort_deduplicate(self) -> Self

Sort and deduplicate the errors in the error stream.

Source§

impl<E: Eq + Hash> ErrorStream<E>

Source

pub fn hash_deduplicate(self) -> Self

Hash and deduplicate the errors in the error stream. The resulting error stream has an arbitrary order.

Trait Implementations§

Source§

impl<E: Clone> Clone for ErrorStream<E>

Source§

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

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<E: Debug> Debug for ErrorStream<E>

Source§

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

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

impl<E: Default> Default for ErrorStream<E>

Source§

fn default() -> ErrorStream<E>

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

impl<E: Display> Display for ErrorStream<E>

Source§

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

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

impl<E> Error for ErrorStream<E>
where Self: Debug + Display,

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<E> From<E> for ErrorStream<E>

Source§

fn from(error: E) -> Self

Converts to this type from the input type.
Source§

impl<E> IntoIterator for ErrorStream<E>

Source§

type Item = <SmallVec<[E; 1]> as IntoIterator>::Item

The type of the elements being iterated over.
Source§

type IntoIter = <SmallVec<[E; 1]> as IntoIterator>::IntoIter

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: PartialEq> PartialEq for ErrorStream<E>

Source§

fn eq(&self, other: &ErrorStream<E>) -> 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<E: Eq> Eq for ErrorStream<E>

Source§

impl<E> StructuralPartialEq for ErrorStream<E>

Auto Trait Implementations§

§

impl<E> Freeze for ErrorStream<E>
where E: Freeze,

§

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

§

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

§

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

§

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

§

impl<E> UnwindSafe for ErrorStream<E>

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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> 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.