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>,
)
| 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> { |