use crate::prelude::*;
#[derive(Clone)]
pub struct SubscribeAll<N, E, C> {
next: N,
error: E,
complete: C,
}
impl<N, E, C> SubscribeAll<N, E, C> {
#[inline(always)]
pub fn new(next: N, error: E, complete: C) -> Self {
SubscribeAll {
next,
error,
complete,
}
}
}
impl<N, E, C> IntoShared for SubscribeAll<N, E, C>
where
Self: Send + Sync + 'static,
{
type Shared = Self;
#[inline(always)]
fn to_shared(self) -> Self::Shared { self }
}
impl<Item, Err, N, E, C> Observer<Item, Err> for SubscribeAll<N, E, C>
where
N: FnMut(&Item),
E: FnMut(&Err),
C: FnMut(),
{
#[inline(always)]
fn next(&mut self, value: &Item) { (self.next)(value); }
#[inline(always)]
fn error(&mut self, err: &Err) { (self.error)(err); }
#[inline(always)]
fn complete(&mut self) { (self.complete)(); }
}
pub trait SubscribableAll<Item, Err, N, E, C> {
type Unsub;
fn subscribe_all(self, next: N, error: E, complete: C) -> Self::Unsub;
}
impl<S, Item, Err, N, E, C> SubscribableAll<Item, Err, N, E, C> for S
where
S: RawSubscribable<
Item,
Err,
Subscriber<SubscribeAll<N, E, C>, LocalSubscription>,
>,
N: FnMut(&Item),
E: FnMut(&Err),
C: FnMut(),
{
type Unsub = S::Unsub;
fn subscribe_all(self, next: N, error: E, complete: C) -> Self::Unsub
where
Self: Sized,
{
let subscriber = Subscriber::local(SubscribeAll {
next,
error,
complete,
});
self.raw_subscribe(subscriber)
}
}