ruchei_callback/
lib.rs

1#![no_std]
2
3//! Callbacks used in [`ruchei`] stream adapters.
4//!
5//! Placed in a separate crate to improve compatibility across [`ruchei`] versions, since the bigger
6//! crate is still at `0.0.X`, at the time of writing, and there are no plans of changing that yet.
7//!
8//! [`ruchei`]: https://docs.rs/ruchei/0.0.81/ruchei/index.html
9
10/// Act when one of inner channels gets closed instead of closing the outer channel. Used with [`multicast`].
11///
12/// Deprecated in favour of [`MultiItem`].
13///
14/// [`multicast`]: https://docs.rs/ruchei/0.0.81/ruchei/multicast/index.html
15/// [`MultiItem`]: https://docs.rs/ruchei/0.0.97/ruchei/multi_item/enum.MultiItem.html
16#[deprecated]
17pub trait OnClose<E>: Clone {
18    /// Get notified about something getting closed (optionally with an error).
19    fn on_close(&self, error: Option<E>);
20}
21
22/// Implemented only for [`Sized`] because stored.
23#[expect(deprecated)]
24impl<E, F: Clone + Fn(Option<E>)> OnClose<E> for F {
25    fn on_close(&self, error: Option<E>) {
26        self(error)
27    }
28}
29
30/// Used with [`ReadCallback`].
31///
32/// Deprecated: the combinator got removed.
33///
34/// [`ReadCallback`]: https://docs.rs/ruchei/0.0.81/ruchei/read_callback/index.html
35#[deprecated]
36pub trait OnItem<T> {
37    /// Receive an item.
38    fn on_item(&self, message: T);
39}
40
41/// Implemented only for [`Sized`] because stored.
42#[expect(deprecated)]
43impl<T, F: Fn(T)> OnItem<T> for F {
44    fn on_item(&self, message: T) {
45        self(message)
46    }
47}
48
49/// Start a timer [`Future`]. Used with [`TimeoutUnused`].
50///
51/// [`Future`]: core::future::Future
52/// [`TimeoutUnused`]: https://docs.rs/ruchei/0.0.81/ruchei/timeout_unused/index.html
53pub trait Start {
54    /// Future created by this factory.
55    type Fut;
56
57    /// Create the future (start a timer).
58    #[must_use]
59    fn make(&mut self) -> Self::Fut;
60}
61
62/// Implemented only for [`Sized`] because stored.
63impl<Fut, F: FnMut() -> Fut> Start for F {
64    type Fut = Fut;
65
66    fn make(&mut self) -> Self::Fut {
67        self()
68    }
69}