karyon_jsonrpc/server/
service.rs

1use std::{future::Future, pin::Pin};
2
3use crate::error::RPCResult;
4
5/// Represents the RPC method
6pub type RPCMethod<'a> = Box<dyn Fn(serde_json::Value) -> RPCMethodOutput<'a> + Send + 'a>;
7type RPCMethodOutput<'a> =
8    Pin<Box<dyn Future<Output = RPCResult<serde_json::Value>> + Send + Sync + 'a>>;
9
10/// Defines the interface for an RPC service.
11pub trait RPCService: Sync + Send {
12    fn get_method(&self, name: &str) -> Option<RPCMethod>;
13    fn name(&self) -> String;
14}