mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-11 04:21:12 +01:00
An another try to implement ErrorPolicy for FnMut
This commit is contained in:
parent
ba8269575b
commit
ea2a2c83d8
1 changed files with 3 additions and 7 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue