rx_rust/operators/creating/
never.rs

1use crate::utils::types::NecessarySendSync;
2use crate::{disposable::subscription::Subscription, observable::Observable, observer::Observer};
3use educe::Educe;
4use std::convert::Infallible;
5
6/// Creates an Observable that emits no items and never terminates.
7/// See <https://reactivex.io/documentation/operators/empty-never-throw.html>
8///
9/// # Examples
10/// ```rust
11/// use rx_rust::{
12///     observable::observable_ext::ObservableExt,
13///     operators::creating::never::Never,
14/// };
15/// use std::convert::Infallible;
16///
17/// let _subscription = Never.subscribe_with_callback(
18///     |value: Infallible| panic!("`Never` should not emit values"),
19///     |_| panic!("`Never` should not terminate"),
20/// );
21/// ```
22#[derive(Educe)]
23#[educe(Debug, Clone)]
24pub struct Never;
25
26impl<'or, 'sub> Observable<'or, 'sub, Infallible, Infallible> for Never {
27    fn subscribe(
28        self,
29        _: impl Observer<Infallible, Infallible> + NecessarySendSync + 'or,
30    ) -> Subscription<'sub> {
31        Subscription::default()
32    }
33}