Skip to main content

rx_rust/subject/
mod.rs

1pub mod async_subject;
2pub mod behavior_subject;
3pub mod publish_subject;
4pub mod replay_subject;
5pub mod subject_observable;
6pub mod unicast_subject;
7
8use crate::{
9    observable::Observable,
10    observer::{Observer, Termination},
11    subject::subject_observable::SubjectObservable,
12};
13
14/// A Subject is a sort of bridge or proxy that acts both as an observer and as an Observable.
15/// See <https://reactivex.io/documentation/subject.html>
16pub trait Subject<'or, T, E>: Observable<'or, T, E> + Observer<T, E> {
17    fn terminated(&self) -> Option<Termination<E>>
18    where
19        E: Clone;
20}
21
22pub trait SubjectExt<'or, T, E>: Sized {
23    /// Converts a subject into an observable, erasing the observer behavior of the subject.
24    fn into_observable(self) -> SubjectObservable<Self> {
25        SubjectObservable::new(self)
26    }
27}
28
29impl<'or, T, E, S> SubjectExt<'or, T, E> for S where S: Subject<'or, T, E> {}