diff options
Diffstat (limited to 'futures')
-rw-r--r-- | futures/src/runtime.rs | 49 | ||||
-rw-r--r-- | futures/src/subscription/tracker.rs | 52 |
2 files changed, 92 insertions, 9 deletions
diff --git a/futures/src/runtime.rs b/futures/src/runtime.rs index 7779e235..96104cd9 100644 --- a/futures/src/runtime.rs +++ b/futures/src/runtime.rs @@ -5,6 +5,50 @@ use crate::{subscription, Executor, Subscription}; use futures::{channel::mpsc, Sink}; use std::marker::PhantomData; +#[cfg(not(target_arch = "wasm32"))] +mod trait_aliases { + use super::*; + + pub trait RuntimeMessage: Send + 'static {} + + impl<T> RuntimeMessage for T where T: Send + 'static {} + + pub trait RuntimeMessageSender<Message: RuntimeMessage>: + Sink<Message, Error = mpsc::SendError> + Unpin + Send + Clone + 'static + { + } + + impl<Message: RuntimeMessage, T> RuntimeMessageSender<Message> for T where + T: Sink<Message, Error = mpsc::SendError> + + Unpin + + Send + + Clone + + 'static + { + } +} + +#[cfg(target_arch = "wasm32")] +mod trait_aliases { + use super::*; + + pub trait RuntimeMessage: 'static {} + + impl<T> RuntimeMessage for T where T: 'static {} + + pub trait RuntimeMessageSender<Message: RuntimeMessage>: + Sink<Message, Error = mpsc::SendError> + Unpin + Clone + 'static + { + } + + impl<Message: RuntimeMessage, T> RuntimeMessageSender<Message> for T where + T: Sink<Message, Error = mpsc::SendError> + Unpin + Clone + 'static + { + } +} + +pub use trait_aliases::{RuntimeMessage, RuntimeMessageSender}; + /// A batteries-included runtime of commands and subscriptions. /// /// If you have an [`Executor`], a [`Runtime`] can be leveraged to run any @@ -23,9 +67,8 @@ where Hasher: std::hash::Hasher + Default, Event: Send + Clone + 'static, Executor: self::Executor, - Sender: - Sink<Message, Error = mpsc::SendError> + Unpin + Send + Clone + 'static, - Message: Send + 'static, + Sender: RuntimeMessageSender<Message>, + Message: RuntimeMessage, { /// Creates a new empty [`Runtime`]. /// diff --git a/futures/src/subscription/tracker.rs b/futures/src/subscription/tracker.rs index 3a8d4a87..01e0c105 100644 --- a/futures/src/subscription/tracker.rs +++ b/futures/src/subscription/tracker.rs @@ -3,6 +3,50 @@ use crate::{BoxFuture, Subscription}; use futures::{channel::mpsc, sink::Sink}; use std::{collections::HashMap, marker::PhantomData}; +#[cfg(not(target_arch = "wasm32"))] +mod trait_aliases { + use super::*; + + pub trait TrackerMessage: Send + 'static {} + + impl<T> TrackerMessage for T where T: Send + 'static {} + + pub trait TrackerMessageReceiver<Message: TrackerMessage>: + Sink<Message, Error = mpsc::SendError> + Unpin + Send + Clone + 'static + { + } + + impl<Message: TrackerMessage, T> TrackerMessageReceiver<Message> for T where + T: Sink<Message, Error = mpsc::SendError> + + Unpin + + Send + + Clone + + 'static + { + } +} + +#[cfg(target_arch = "wasm32")] +mod trait_aliases { + use super::*; + + pub trait TrackerMessage: 'static {} + + impl<T> TrackerMessage for T where T: 'static {} + + pub trait TrackerMessageReceiver<Message: TrackerMessage>: + Sink<Message, Error = mpsc::SendError> + Unpin + Clone + 'static + { + } + + impl<Message: TrackerMessage, T> TrackerMessageReceiver<Message> for T where + T: Sink<Message, Error = mpsc::SendError> + Unpin + Clone + 'static + { + } +} + +pub use trait_aliases::{TrackerMessage, TrackerMessageReceiver}; + /// A registry of subscription streams. /// /// If you have an application that continuously returns a [`Subscription`], @@ -57,12 +101,8 @@ where receiver: Receiver, ) -> Vec<BoxFuture<()>> where - Message: 'static + Send, - Receiver: 'static - + Sink<Message, Error = mpsc::SendError> - + Unpin - + Send - + Clone, + Message: TrackerMessage, + Receiver: TrackerMessageReceiver<Message>, { use futures::{future::FutureExt, stream::StreamExt}; |