aboutsummaryrefslogtreecommitdiff
path: root/src/endpoint.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/endpoint.rs')
-rw-r--r--src/endpoint.rs22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/endpoint.rs b/src/endpoint.rs
index e6b2236..3f292d9 100644
--- a/src/endpoint.rs
+++ b/src/endpoint.rs
@@ -19,7 +19,7 @@ pub trait EndpointHandler<M>: Send + Sync
where
M: Message,
{
- async fn handle(self: &Arc<Self>, m: &M, from: NodeID) -> M::Response;
+ async fn handle(self: &Arc<Self>, m: M, from: NodeID) -> M::Response;
}
/// If one simply wants to use an endpoint in a client fashion,
@@ -28,7 +28,7 @@ where
/// it will panic if it is ever made to handle request.
#[async_trait]
impl<M: Message + 'static> 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.");
}
}
@@ -81,19 +81,16 @@ where
/// Call this endpoint on a remote node (or on the local node,
/// for that matter)
- pub async fn call<B>(
+ pub async fn call(
&self,
target: &NodeID,
- req: B,
+ req: M,
prio: RequestPriority,
- ) -> Result<<M as Message>::Response, Error>
- where
- B: Borrow<M> + Send + Sync,
- {
+ ) -> Result<<M as Message>::Response, Error> {
if *target == self.netapp.id {
match self.handler.load_full() {
None => Err(Error::NoHandler),
- Some(h) => Ok(h.handle(req.borrow(), self.netapp.id).await),
+ Some(h) => Ok(h.handle(req, self.netapp.id).await),
}
} else {
let conn = self
@@ -152,10 +149,11 @@ where
None => Err(Error::NoHandler),
Some(h) => {
let req = rmp_serde::decode::from_read_ref(buf)?;
- let req = M::deserialize_msg(req, stream).await;
- let res = h.handle(&req, from).await;
+ let req = M::from_parts(req, stream);
+ let res = h.handle(req, from).await;
+ let (res, res_stream) = res.into_parts();
let res_bytes = rmp_to_vec_all_named(&res)?;
- Ok(res_bytes)
+ Ok((res_bytes, res_stream))
}
}
}