An another try to implement ErrorPolicy for FnMut

This commit is contained in:
Temirkhan Myrzamadi 2019-11-01 22:09:27 +06:00
parent ba8269575b
commit ea2a2c83d8

View file

@ -8,18 +8,14 @@ pub trait ErrorPolicy<E> {
async fn handle_error(&mut self, error: E);
}
/// A convenient structure with an error-handling closure. Implements
/// `ErrorPolicy`.
pub struct FnErrorPolicy<F>(pub F);
#[async_trait]
impl<E, F, Fut> ErrorPolicy<E> for FnErrorPolicy<F>
impl<E, F, Fut> ErrorPolicy<E> for F
where
F: FnMut(E) -> Fut + Send,
Fut: Future<Output = ()>,
Fut: Future<Output = ()> + Send,
E: Send,
{
async fn handle_error(&mut self, error: E) {
self.0(error);
self(error).await;
}
}