MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / add_extra_errors

Method add_extra_errors

crates/data-structures/src/error_stream.rs:133–151  ·  view source on GitHub ↗

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.

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

Source from the content-addressed store, hash-verified

131 /// If there are errors, and the result is `Err`, the errors are added to the stream.
132 /// If there are errors, and the result is `Ok`, the `Ok` value is discarded, and the errors are returned in a stream.
133 pub fn add_extra_errors<T>(
134 result: Result<T, ErrorStream<E>>,
135 extra_errors: impl IntoIterator<Item = E>,
136 ) -> Result<T, ErrorStream<E>> {
137 match result {
138 Ok(value) => {
139 let errors: SmallVec<[E; 1]> = extra_errors.into_iter().collect();
140 if errors.is_empty() {
141 Ok(value)
142 } else {
143 Err(ErrorStream(errors))
144 }
145 }
146 Err(mut errors) => {
147 errors.extend(extra_errors);
148 Err(errors)
149 }
150 }
151 }
152
153 /// Returns an iterator over the errors in the stream.
154 pub fn iter(&self) -> impl Iterator<Item = &E> {

Callers

nothing calls this directly

Calls 7

ErrorStreamClass · 0.85
OkFunction · 0.50
ErrFunction · 0.50
collectMethod · 0.45
into_iterMethod · 0.45
is_emptyMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected