pub trait CollectAllErrors {
type Item;
type Error;
// Required method
fn collect_all_errors<C: FromIterator<Self::Item>>(
self,
) -> Result<C, ErrorStream<Self::Error>>;
}Expand description
A trait for collecting errors from an iterator of results, returning all errors if anything failed.
Required Associated Types§
Required Methods§
Sourcefn collect_all_errors<C: FromIterator<Self::Item>>(
self,
) -> Result<C, ErrorStream<Self::Error>>
fn collect_all_errors<C: FromIterator<Self::Item>>( self, ) -> Result<C, ErrorStream<Self::Error>>
Collect errors from an iterator of results into a single error stream.
If all results are Ok, returns the collected values. Otherwise,
combine all errors into a single error stream, and return it.
You CANNOT use the standard library function Result<T, ErrorStream<E>>::collect() for this,
as it will return the FIRST error it encounters, rather than collecting all errors!
The collection can be anything that implements FromIterator.
Example usage:
use spacetimedb_data_structures::error_stream::{
ErrorStream,
CollectAllErrors
};
use std::collections::HashSet;
enum MyError { /* ... */ }
fn operation(
data: String,
checksum: u32
) -> Result<i32, ErrorStream<MyError>> {
/* ... */
}
fn many_operations(
data: Vec<(String, u32)>
) -> Result<HashSet<i32>, ErrorStream<MyError>> {
data
.into_iter()
.map(|(data, checksum)| operation(data, checksum))
.collect_all_errors::<HashSet<_>>()
}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.