use std::future::Future;
use prost::Message;
use crate::public::generated::metadata::Method;
use crate::public::generated::rpc_support::GestaltError;
pub trait UnaryTransport: Send + Sync {
fn unary<Req, Resp>(
&self,
method: &Method,
request: &Req,
response: &mut Resp,
) -> impl Future<Output = Result<(), GestaltError>> + Send
where
Req: Message + Clone + Send + Sync + 'static,
Resp: Message + Default + Send + 'static;
}
pub trait SyncUnaryTransport: Send + Sync {
fn unary<Req, Resp>(
&self,
method: &Method,
request: &Req,
response: &mut Resp,
) -> Result<(), GestaltError>
where
Req: Message + Clone + Send + Sync + 'static,
Resp: Message + Default + Send + 'static;
}
pub trait GrpcCapable: UnaryTransport {}
pub trait SyncGrpcCapable: SyncUnaryTransport {}
pub trait ServerStreamRecv<Resp: Message + Default + Send + 'static>: Send {
fn recv(
&mut self,
) -> std::pin::Pin<Box<dyn Future<Output = Result<Option<Resp>, GestaltError>> + Send + '_>>;
}
pub trait ServerStreamingTransport: Send + Sync {
fn server_stream<Req, Resp>(
&self,
method: &Method,
request: &Req,
) -> impl Future<Output = Result<Box<dyn ServerStreamRecv<Resp>>, GestaltError>> + Send
where
Req: Message + Clone + Send + Sync + 'static,
Resp: Message + Default + Send + 'static;
}
pub trait SyncServerStreamingTransport: Send + Sync {
fn server_stream<Req, Resp>(
&self,
method: &Method,
request: &Req,
) -> Result<Box<dyn ServerStreamRecv<Resp>>, GestaltError>
where
Req: Message + Clone + Send + Sync + 'static,
Resp: Message + Default + Send + 'static;
}