xboot/
lib.rs

1use aok::Result;
2pub use gensym::gensym;
3pub use linkme::distributed_slice;
4pub use paste::paste;
5pub use tokio;
6
7pub type Task = tokio::task::JoinHandle<Result<()>>;
8
9pub type AsyncFn = fn() -> Task;
10
11#[distributed_slice]
12pub static ASYNC: [AsyncFn];
13
14pub async fn init() -> Result<()> {
15  for i in ASYNC {
16    i().await??;
17  }
18  Ok(())
19}
20
21#[macro_export]
22macro_rules! add {
23  ($init:expr) => {
24    $crate::gensym! {$crate::add! {$init}}
25  };
26  ($id:expr, $init:expr) => {
27    $crate::paste! {
28    fn [<xboot_init_ $id>]() -> $crate::Task {
29      $crate::tokio::task::spawn(async {
30        $init;
31        Ok(())
32      })
33    }
34    #[$crate::distributed_slice($crate::ASYNC)]
35    static [<ASYNC_INIT_ $id>]: $crate::AsyncFn = [<xboot_init_ $id>];
36    }
37  };
38}