rx_rust/disposable/chain_disposal.rs
1use crate::disposable::Disposable;
2
3/// A disposal that disposes `first`, then `second`.
4///
5/// The front-to-back dispose order is a guarantee, not an implementation detail:
6/// operators encode their semantics in it. For example, `DoBeforeDisposal` places
7/// its callback in `first` to run before the source's disposal, while
8/// `DoAfterDisposal` places it in `second` to run after.
9pub struct ChainDisposal<D1, D2> {
10 first: D1,
11 second: D2,
12}
13
14impl<D1, D2> ChainDisposal<D1, D2> {
15 pub fn new(first: D1, second: D2) -> Self {
16 Self { first, second }
17 }
18}
19
20impl<D1, D2> Disposable for ChainDisposal<D1, D2>
21where
22 D1: Disposable,
23 D2: Disposable,
24{
25 fn dispose(self) {
26 self.first.dispose();
27 self.second.dispose();
28 }
29}