add streaming body to requests and responses #3

Merged
lx merged 64 commits from stream-body into main 2022-09-13 10:56:54 +00:00
2 changed files with 5 additions and 5 deletions
Showing only changes of commit cbc21e40ac - Show all commits

View file

@ -27,7 +27,7 @@ where
/// use the unit type `()` as the handler type: /// use the unit type `()` as the handler type:
/// it will panic if it is ever made to handle request. /// it will panic if it is ever made to handle request.
#[async_trait] #[async_trait]
impl<M: Message + 'static> EndpointHandler<M> for () { impl<M: Message> EndpointHandler<M> for () {
async fn handle(self: &Arc<()>, _m: &M, _from: NodeID) -> M::Response { async fn handle(self: &Arc<()>, _m: &M, _from: NodeID) -> M::Response {
panic!("This endpoint should not have a local handler."); panic!("This endpoint should not have a local handler.");
} }
@ -50,7 +50,7 @@ where
impl<T, M> StreamingEndpointHandler<M> for T impl<T, M> StreamingEndpointHandler<M> for T
where where
T: EndpointHandler<M>, T: EndpointHandler<M>,
M: Message + 'static, M: Message,
{ {
async fn handle(self: &Arc<Self>, mut m: Req<M>, from: NodeID) -> Resp<M> { async fn handle(self: &Arc<Self>, mut m: Req<M>, from: NodeID) -> Resp<M> {
// Immediately drop stream to avoid backpressure if a stream was sent // Immediately drop stream to avoid backpressure if a stream was sent
@ -177,7 +177,7 @@ where
#[async_trait] #[async_trait]
impl<M, H> GenericEndpoint for EndpointArc<M, H> impl<M, H> GenericEndpoint for EndpointArc<M, H>
where where
M: Message + 'static, M: Message,
H: StreamingEndpointHandler<M> + 'static, H: StreamingEndpointHandler<M> + 'static,
{ {
async fn handle(&self, req_enc: ReqEnc, from: NodeID) -> Result<RespEnc, Error> { async fn handle(&self, req_enc: ReqEnc, from: NodeID) -> Result<RespEnc, Error> {

View file

@ -42,8 +42,8 @@ pub const PRIO_SECONDARY: RequestPriority = 0x01;
/// This trait should be implemented by all messages your application /// This trait should be implemented by all messages your application
/// wants to handle /// wants to handle
pub trait Message: Serialize + for<'de> Deserialize<'de> + Send + Sync { pub trait Message: Serialize + for<'de> Deserialize<'de> + Send + Sync + 'static {
type Response: Serialize + for<'de> Deserialize<'de> + Send + Sync; type Response: Serialize + for<'de> Deserialize<'de> + Send + Sync + 'static;
} }
// ---- // ----