rx_rust/operators/others/
map_infallible_to_value.rs1use crate::utils::types::NecessarySendSync;
2use crate::{
3 disposable::subscription::Subscription,
4 observable::Observable,
5 observer::{Observer, Termination},
6 utils::types::MarkerType,
7};
8use educe::Educe;
9use std::{convert::Infallible, marker::PhantomData};
10
11#[derive(Educe)]
36#[educe(Debug, Clone)]
37pub struct MapInfallibleToValue<T, OE> {
38 source: OE,
39 _marker: MarkerType<T>,
40}
41
42impl<T, OE> MapInfallibleToValue<T, OE> {
43 pub fn new(source: OE) -> Self {
44 Self {
45 source,
46 _marker: PhantomData,
47 }
48 }
49}
50
51impl<'or, 'sub, T, E, OE> Observable<'or, 'sub, T, E> for MapInfallibleToValue<T, OE>
52where
53 T: 'or,
54 OE: Observable<'or, 'sub, Infallible, E>,
55{
56 fn subscribe(self, observer: impl Observer<T, E> + NecessarySendSync + 'or) -> Subscription<'sub> {
57 let observer = MapInfallibleToValueObserver {
58 observer,
59 _marker: PhantomData,
60 };
61 self.source.subscribe(observer)
62 }
63}
64
65struct MapInfallibleToValueObserver<T, OR> {
66 observer: OR,
67 _marker: MarkerType<T>,
68}
69
70impl<T, E, OR> Observer<Infallible, E> for MapInfallibleToValueObserver<T, OR>
71where
72 OR: Observer<T, E>,
73{
74 fn on_next(&mut self, _: Infallible) {
75 unreachable!()
76 }
77
78 fn on_termination(self, termination: Termination<E>) {
79 self.observer.on_termination(termination);
80 }
81}