Various style fixes

* Removed type bounds from struct declaration
* Simplified <S as Storage<D>>::Error to S::Error
* Simplified complex type to BoxFuture
This commit is contained in:
Maximilian Siling 2020-03-10 23:28:38 +03:00
parent fff1e55a58
commit f9b3a4836e

View file

@ -5,9 +5,9 @@ use crate::dispatching::{
}, },
DispatcherHandler, DispatcherHandlerCx, DispatcherHandler, DispatcherHandlerCx,
}; };
use std::{convert::Infallible, future::Future, marker::PhantomData, pin::Pin}; use std::{convert::Infallible, marker::PhantomData};
use futures::StreamExt; use futures::{future::BoxFuture, StreamExt};
use tokio::sync::mpsc; use tokio::sync::mpsc;
use lockfree::map::Map; use lockfree::map::Map;
@ -23,10 +23,7 @@ use std::sync::{Arc, Mutex};
/// ///
/// [`Dispatcher`]: crate::dispatching::Dispatcher /// [`Dispatcher`]: crate::dispatching::Dispatcher
/// [`DispatcherHandler`]: crate::dispatching::DispatcherHandler /// [`DispatcherHandler`]: crate::dispatching::DispatcherHandler
pub struct DialogueDispatcher<D, S, H, Upd> pub struct DialogueDispatcher<D, S, H, Upd> {
where
S: Storage<D> + Send + Sync + 'static,
{
storage: Arc<S>, storage: Arc<S>,
handler: Arc<H>, handler: Arc<H>,
_phantom: PhantomData<Mutex<D>>, _phantom: PhantomData<Mutex<D>>,
@ -63,14 +60,11 @@ where
impl<D, S, H, Upd> DialogueDispatcher<D, S, H, Upd> impl<D, S, H, Upd> DialogueDispatcher<D, S, H, Upd>
where where
H: DialogueDispatcherHandler<Upd, D, <S as Storage<D>>::Error> H: DialogueDispatcherHandler<Upd, D, S::Error> + Send + Sync + 'static,
+ Send
+ Sync
+ 'static,
Upd: GetChatId + Send + 'static, Upd: GetChatId + Send + 'static,
D: Default + Send + 'static, D: Default + Send + 'static,
S: Storage<D> + Send + Sync + 'static, S: Storage<D> + Send + Sync + 'static,
<S as Storage<D>>::Error: Send + 'static, S::Error: Send + 'static,
{ {
/// Creates a dispatcher with the specified `handler` and `storage`. /// Creates a dispatcher with the specified `handler` and `storage`.
#[must_use] #[must_use]
@ -142,19 +136,16 @@ where
impl<D, S, H, Upd> DispatcherHandler<Upd> for DialogueDispatcher<D, S, H, Upd> impl<D, S, H, Upd> DispatcherHandler<Upd> for DialogueDispatcher<D, S, H, Upd>
where where
H: DialogueDispatcherHandler<Upd, D, <S as Storage<D>>::Error> H: DialogueDispatcherHandler<Upd, D, S::Error> + Send + Sync + 'static,
+ Send
+ Sync
+ 'static,
Upd: GetChatId + Send + 'static, Upd: GetChatId + Send + 'static,
D: Default + Send + 'static, D: Default + Send + 'static,
S: Storage<D> + Send + Sync + 'static, S: Storage<D> + Send + Sync + 'static,
<S as Storage<D>>::Error: Send + 'static, S::Error: Send + 'static,
{ {
fn handle( fn handle(
self, self,
updates: mpsc::UnboundedReceiver<DispatcherHandlerCx<Upd>>, updates: mpsc::UnboundedReceiver<DispatcherHandlerCx<Upd>>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'static>> ) -> BoxFuture<'static, ()>
where where
DispatcherHandlerCx<Upd>: 'static, DispatcherHandlerCx<Upd>: 'static,
{ {