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]
17#[must_use = "callbacks must be called"]
18pub trait OnClose<E>: Clone {
19    /// Get notified about something getting closed (optionally with an error).
20    fn on_close(&self, error: Option<E>);
21}
22
23/// Implemented only for [`Sized`] because stored.
24#[expect(deprecated)]
25impl<E, F: Clone + Fn(Option<E>)> OnClose<E> for F {
26    fn on_close(&self, error: Option<E>) {
27        self(error)
28    }
29}
30
31/// Used with [`ReadCallback`].
32///
33/// Deprecated: the combinator got removed.
34///
35/// [`ReadCallback`]: https://docs.rs/ruchei/0.0.81/ruchei/read_callback/index.html
36#[deprecated]
37#[must_use = "callbacks must be called"]
38pub trait OnItem<T> {
39    /// Receive an item.
40    fn on_item(&self, message: T);
41}
42
43/// Implemented only for [`Sized`] because stored.
44#[expect(deprecated)]
45impl<T, F: Fn(T)> OnItem<T> for F {
46    fn on_item(&self, message: T) {
47        self(message)
48    }
49}
50
51/// Start a timer [`Future`]. Used with [`TimeoutUnused`].
52///
53/// [`Future`]: core::future::Future
54/// [`TimeoutUnused`]: https://docs.rs/ruchei/0.0.81/ruchei/timeout_unused/index.html
55#[must_use = "callbacks must be called"]
56pub trait Start {
57    /// Future created by this factory.
58    type Fut;
59
60    /// Create the future (start a timer).
61    #[must_use]
62    fn make(&mut self) -> Self::Fut;
63}
64
65/// Implemented only for [`Sized`] because stored.
66impl<Fut, F: FnMut() -> Fut> Start for F {
67    type Fut = Fut;
68
69    fn make(&mut self) -> Self::Fut {
70        self()
71    }
72}