rx_rust/disposable/
bound_drop_disposal.rs1use crate::disposable::Disposable;
2
3pub struct BoundDropDisposal<T>(Option<T>)
5where
6 T: Disposable;
7
8impl<T> BoundDropDisposal<T>
9where
10 T: Disposable,
11{
12 pub fn new(disposal: T) -> Self {
13 Self(Some(disposal))
14 }
15}
16
17impl<T> Disposable for BoundDropDisposal<T>
18where
19 T: Disposable,
20{
21 fn dispose(self) {
22 }
24}
25
26impl<T> Drop for BoundDropDisposal<T>
27where
28 T: Disposable,
29{
30 fn drop(&mut self) {
31 if let Some(disposal) = self.0.take() {
32 disposal.dispose();
33 }
34 }
35}