use std::{any::TypeId, collections::BTreeMap};
use lazy_static::lazy_static;
use linkme::distributed_slice;
use crate::QubitHandler;
#[distributed_slice]
pub static HANDLER_DEFINITIONS: [fn() -> (TypeId, HandlerMeta)];
lazy_static! {
static ref HANDLER_DEFINITIONS_MAP: BTreeMap<TypeId, HandlerMeta> = HANDLER_DEFINITIONS
.into_iter()
.map(|def_fn| def_fn())
.collect();
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum HandlerKind {
Query,
Mutation,
Subscription,
}
#[derive(Clone, Debug)]
pub struct HandlerMeta {
pub kind: HandlerKind,
pub name: &'static str,
pub param_names: &'static [&'static str],
}
impl HandlerMeta {
pub(crate) fn of<F, Ctx, MSig>(#[allow(unused)] handler: &F) -> &'static Self
where
F: QubitHandler<Ctx, MSig>,
{
HANDLER_DEFINITIONS_MAP.get(&TypeId::of::<F>()).unwrap()
}
}