kutil_std/error/
recipient.rs

1//
2// ErrorRecipient
3//
4
5/// A recipient of errors.
6pub trait ErrorRecipient<ErrorT> {
7    /// Gives an error to the recipient.
8    ///
9    /// Implementations may swallow the error (e.g. to accumulate it) or
10    /// return it (fail-fast).
11    fn give(&mut self, error: impl Into<ErrorT>) -> Result<(), ErrorT>;
12}
13
14//
15// FailFastErrorRecipient
16//
17
18/// [ErrorRecipient] that fails on the first given error.
19pub struct FailFastErrorRecipient;
20
21impl<ErrorT> ErrorRecipient<ErrorT> for FailFastErrorRecipient {
22    fn give(&mut self, error: impl Into<ErrorT>) -> Result<(), ErrorT> {
23        Err(error.into())
24    }
25}