use std::path::Path;
use ts_rs::{Dependency, ExportError};
use crate::{builder::RpcBuilder, util::QubitType, HandlerType};
pub trait Handler<AppCtx> {
fn register(rpc_builder: RpcBuilder<AppCtx>) -> RpcBuilder<AppCtx>;
fn get_type() -> HandlerType;
fn export_all_dependencies_to(out_dir: &Path) -> Result<Vec<Dependency>, ExportError>;
fn qubit_types() -> Vec<QubitType>;
}
#[derive(Clone)]
pub(crate) struct HandlerCallbacks<Ctx> {
pub register: fn(RpcBuilder<Ctx>) -> RpcBuilder<Ctx>,
pub get_type: fn() -> HandlerType,
pub export_all_dependencies_to: fn(&Path) -> Result<Vec<Dependency>, ExportError>,
pub qubit_types: fn() -> Vec<QubitType>,
}
impl<Ctx> HandlerCallbacks<Ctx>
where
Ctx: 'static + Send + Sync + Clone,
{
pub fn from_handler<H: Handler<Ctx>>(_handler: H) -> Self {
Self {
register: H::register,
get_type: H::get_type,
export_all_dependencies_to: H::export_all_dependencies_to,
qubit_types: H::qubit_types,
}
}
}