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