Skip to main content

backyard_core/
registry.rs

1use crate::{error::Result, job::JobContext};
2use std::collections::HashMap;
3use std::future::Future;
4use std::pin::Pin;
5
6pub struct JobRegistration {
7    pub name: &'static str,
8    pub handler:
9        fn(raw: &[u8], ctx: JobContext) -> Pin<Box<dyn Future<Output = Result<()>> + Send>>,
10}
11
12inventory::collect!(JobRegistration);
13
14pub fn build_dispatch_table(
15) -> HashMap<&'static str, fn(&[u8], JobContext) -> Pin<Box<dyn Future<Output = Result<()>> + Send>>>
16{
17    inventory::iter::<JobRegistration>()
18        .map(|r| (r.name, r.handler))
19        .collect()
20}