rx_rust/subject/
subject_observable.rs

1use super::Subject;
2use crate::utils::types::NecessarySendSync;
3use crate::{disposable::subscription::Subscription, observable::Observable, observer::Observer};
4use educe::Educe;
5
6/// An observable from a subject without the observer behavior of the subject.
7#[derive(Educe)]
8#[educe(Debug, Clone)]
9pub struct SubjectObservable<S>(S);
10
11impl<S> SubjectObservable<S> {
12    pub fn new(subject: S) -> Self {
13        Self(subject)
14    }
15}
16
17impl<'or, 'sub, T, E, S> Observable<'or, 'sub, T, E> for SubjectObservable<S>
18where
19    S: Subject<'or, 'sub, T, E>,
20{
21    fn subscribe(self, observer: impl Observer<T, E> + NecessarySendSync + 'or) -> Subscription<'sub> {
22        self.0.subscribe(observer)
23    }
24}