pub struct Responder<'i, Rq, Rp> { /* private fields */ }Expand description
Responder end of a channel
For a static Channel or Interchange,
the responder uses a 'static lifetime parameter
Implementations§
Source§impl<'i, Rq, Rp> Responder<'i, Rq, Rp>
impl<'i, Rq, Rp> Responder<'i, Rq, Rp>
Sourcepub fn callback_mut(&mut self) -> &mut Callback
pub fn callback_mut(&mut self) -> &mut Callback
Allows to set a callback that is called when a response has been sent.
The callback is called by Responder::respond and Responder::send_response.
pub fn channel(&self) -> &'i Channel<Rq, Rp>
Sourcepub fn state(&self) -> State
pub fn state(&self) -> State
Current state of the channel.
Informational only!
The responder may change this state between calls, internally atomics ensure correctness.
Sourcepub fn with_request<R>(&self, f: impl FnOnce(&Rq) -> R) -> Result<R, Error>
pub fn with_request<R>(&self, f: impl FnOnce(&Rq) -> R) -> Result<R, Error>
If there is a request waiting, perform an operation with a reference to it
This may be called only once as it move the state to BuildingResponse.
If you need copies, use take_request
Sourcepub fn request(&self) -> Result<&Rq, Error>
pub fn request(&self) -> Result<&Rq, Error>
If there is a request waiting, obtain a reference to it
This may be called multiple times.
Sourcepub fn take_request(&mut self) -> Option<Rq>
pub fn take_request(&mut self) -> Option<Rq>
If there is a request waiting, take a reference to it out
This may be called only once as it move the state to BuildingResponse. If you need copies, clone the request.
pub fn is_canceled(&self) -> bool
pub fn acknowledge_cancel(&self) -> Result<(), Error>
Sourcepub fn respond(&mut self, response: Rp) -> Result<(), Error>
pub fn respond(&mut self, response: Rp) -> Result<(), Error>
Respond to a request.
If efficiency is a concern, or responses need multiple steps to
construct, use with_response_mut or response_mut and send_response.
If the response has been sent succesfully, this functions calls the callback set with
Responder::callback_mut.
Source§impl<Rq, Rp> Responder<'_, Rq, Rp>where
Rp: Default,
impl<Rq, Rp> Responder<'_, Rq, Rp>where
Rp: Default,
Sourcepub fn with_response_mut<R>(
&mut self,
f: impl FnOnce(&mut Rp) -> R,
) -> Result<R, Error>
pub fn with_response_mut<R>( &mut self, f: impl FnOnce(&mut Rp) -> R, ) -> Result<R, Error>
Initialize a response with its default values and mutates it with f
This is usefull to build large structures in-place
Sourcepub fn response_mut(&mut self) -> Result<&mut Rp, Error>
pub fn response_mut(&mut self) -> Result<&mut Rp, Error>
Initialize a response with its default values and and return a mutable reference to it
This is usefull to build large structures in-place
Sourcepub fn send_response(&mut self) -> Result<(), Error>
pub fn send_response(&mut self) -> Result<(), Error>
Send a response that was already placed in the channel using response_mut or
with_response_mut.
If the response has been sent succesfully, this functions calls the callback set with
Responder::callback_mut.