use alux_ext::{ApplyAlg, ext};
pub trait JsonRpcAlg {
type Methods;
fn jsonrpc_empty(&self) -> Self::Methods;
fn jsonrpc_merge(&self, left: Self::Methods, right: Self::Methods) -> Self::Methods;
}
pub trait JsonRpcMethodAlg<Context, Args, Output> {
fn finish_jsonrpc_positional_method<Handler>(&self, name: &'static str, handler: Handler) -> Self::Methods
where
Self: JsonRpcAlg,
Handler: ApplyAlg<Context, Args, Output = Output> + Send + Sync + 'static;
fn finish_jsonrpc_named_method<Handler>(
&self,
name: &'static str,
arg_names: &'static [&'static str],
handler: Handler,
) -> Self::Methods
where
Self: JsonRpcAlg,
Handler: ApplyAlg<Context, Args, Output = Output> + Send + Sync + 'static;
}
pub trait JsonRpcProgramAlg<Compiler> {
type Methods;
fn compile_jsonrpc(self, compiler: &Compiler) -> Self::Methods;
}
pub trait JsonRpcApiAlg: JsonRpcAlg {}
impl<This> JsonRpcApiAlg for This where This: JsonRpcAlg {}
#[ext(name = JsonRpcProgramExt)]
pub impl<This> This {
fn compile_jsonrpc<Program>(&self, program: Program) -> Program::Methods
where
Program: JsonRpcProgramAlg<This>,
{
program.compile_jsonrpc(self)
}
}