karyon_jsonrpc/server/
pubsub_service.rs

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