1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
pub extern crate atomic_take;
pub extern crate inventory;
use atomic_take::AtomicTake;
pub struct BootBox {
pub boot_fn: AtomicTake<Box<dyn FnOnce()>>,
}
inventory::collect!(BootBox);
pub fn boot() {
for boot_box in inventory::iter::<BootBox> {
if let Some(boot_fn) = boot_box.boot_fn.take() {
boot_fn();
}
}
}
#[macro_export]
macro_rules! call_on_boot {
($boot:block) => {
use $crate::{atomic_take::AtomicTake, inventory, BootBox};
inventory::submit! {
BootBox {
boot_fn: AtomicTake::new(Box::new(|| $boot_fn))
}
}
};
}