iroh_test/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//! Internal utilities to support testing.

pub mod hexdump;
pub mod logging;

// #[derive(derive_more::Debug)]
#[allow(missing_debug_implementations)]
pub struct CallOnDrop(Option<Box<dyn FnOnce()>>);

impl CallOnDrop {
    pub fn new(f: impl FnOnce() + 'static) -> Self {
        Self(Some(Box::new(f)))
    }
}

impl Drop for CallOnDrop {
    fn drop(&mut self) {
        if let Some(f) = self.0.take() {
            f();
        }
    }
}