rx_core_common/subject.rs
1use crate::{
2 Observable, ObserverInput, PrimaryCategorySubject, RxObserver, SubscriptionLike,
3 UpgradeableObserver,
4};
5
6/// A Subject is something that is an Observable and Observer (Subscriber) at
7/// the same time. Signals pushed into it will be received by the subscriptions
8/// made from it, broadcasting them.
9///
10/// Subjects do not actually implement [SubscriptionLike][crate::SubscriptionLike]
11/// despite them having an `unsubscribe` method and being closable.
12/// The reason is that subjects do not and can't own resources, that's the job
13/// of the subscriptions you make with them. This allows subjects to be safely
14/// droppable without having to call `unsubscribe` on them even in a
15/// [DropUnsafeSubscriptionContext][crate::DropUnsafeSubscriptionContext].
16/// The `unsubscribe` method on subjects is only there for users to mass
17/// unsubscribe every subscription made from the subjects.
18pub trait SubjectLike:
19 Observable<PrimaryCategory = PrimaryCategorySubject>
20 + RxObserver
21 + SubscriptionLike
22 + UpgradeableObserver
23{
24}
25
26impl<T> SubjectLike for T
27where
28 T: Observable<PrimaryCategory = PrimaryCategorySubject>
29 + RxObserver
30 + SubscriptionLike
31 + UpgradeableObserver,
32 <T as ObserverInput>::In: Clone,
33 <T as ObserverInput>::InError: Clone,
34{
35}