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