use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use anyhow::Result;
use async_trait::async_trait;
use bytes::Bytes;
#[derive(Debug, Clone)]
pub struct RpcMethodDef {
pub name: String,
pub description: String,
}
impl RpcMethodDef {
pub fn new(name: impl Into<String>, description: impl Into<String>) -> Self {
Self {
name: name.into(),
description: description.into(),
}
}
}
pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
pub type RpcHandler = Arc<dyn Fn(Bytes) -> BoxFuture<'static, Result<Bytes>> + Send + Sync>;
#[async_trait]
pub trait RpcRegistrar: Send + Sync + 'static {
async fn register_raw(&self, name: String, handler: RpcHandler);
}