diff --git a/base_layer/service_framework/src/lib.rs b/base_layer/service_framework/src/lib.rs index 1b6143d3ed..f2642c15f8 100644 --- a/base_layer/service_framework/src/lib.rs +++ b/base_layer/service_framework/src/lib.rs @@ -52,7 +52,7 @@ //! // At the same time receive the request and reply //! async move { //! let req_context = receiver.next().await.unwrap(); -//! let msg = req_context.request().unwrap().clone(); +//! let msg = req_context.request().clone(); //! req_context.reply(msg.to_uppercase()); //! } //! ); diff --git a/base_layer/service_framework/src/reply_channel.rs b/base_layer/service_framework/src/reply_channel.rs index f69374405b..983fd0afe3 100644 --- a/base_layer/service_framework/src/reply_channel.rs +++ b/base_layer/service_framework/src/reply_channel.rs @@ -131,37 +131,25 @@ impl Future for TransportResponseFuture { /// request. pub struct RequestContext { reply_tx: oneshot::Sender, - request: Option, + request: TReq, } impl RequestContext { /// Create a new RequestContect pub fn new(request: TReq, reply_tx: oneshot::Sender) -> Self { - Self { - request: Some(request), - reply_tx, - } + Self { request, reply_tx } } /// Return a reference to the request object. None is returned after take_request has /// been called. - pub fn request(&self) -> Option<&TReq> { - self.request.as_ref() - } - - /// Take ownership of the request object, if ownership has not already been taken, - /// otherwise None is returned. - pub fn take_request(&mut self) -> Option { - self.request.take() + pub fn request(&self) -> &TReq { + &self.request } /// Consume this object and return it's parts. Namely, the request object and /// the reply oneshot channel. pub fn split(self) -> (TReq, oneshot::Sender) { - ( - self.request.expect("RequestContext must be initialized with a request"), - self.reply_tx, - ) + (self.request, self.reply_tx) } /// Sends a reply to the caller