rx_rust/disposable/callback_disposal.rs
1use crate::disposable::Disposable;
2use educe::Educe;
3
4/// A disposal that calls a callback when disposed.
5#[derive(Educe)]
6#[educe(Debug)]
7pub struct CallbackDisposal<F: FnOnce()>(F);
8
9impl<F: FnOnce()> CallbackDisposal<F> {
10 pub fn new(callback: F) -> Self {
11 Self(callback)
12 }
13}
14impl<F: FnOnce()> Disposable for CallbackDisposal<F> {
15 fn dispose(self) {
16 self.0();
17 }
18}