//! Generate events asynchronously for you application. /// An event subscription. pub struct Subscription { definitions: Vec>>, } impl Subscription { pub fn none() -> Self { Self { definitions: Vec::new(), } } pub fn batch(subscriptions: impl Iterator>) -> Self { Self { definitions: subscriptions .flat_map(|subscription| subscription.definitions) .collect(), } } pub fn definitions(self) -> Vec>> { self.definitions } } impl From for Subscription where A: Definition + 'static, { fn from(definition: A) -> Self { Self { definitions: vec![Box::new(definition)], } } } /// The definition of an event subscription. pub trait Definition { type Message; fn id(&self) -> u64; fn stream( &self, ) -> ( futures::stream::BoxStream<'static, Self::Message>, Box, ); } pub trait Handle { fn cancel(&mut self); } impl std::fmt::Debug for Subscription { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("Command").finish() } }