interchange

Struct Responder

Source
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>

Source

pub fn channel(&self) -> &'i Channel<Rq, Rp>

Source

pub fn state(&self) -> State

Current state of the channel.

Informational only!

The responder may change this state between calls, internally atomics ensure correctness.

Source

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

Source

pub fn request(&self) -> Result<&Rq, Error>

If there is a request waiting, obtain a reference to it

This may be called multiple times.

Source

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.

Source

pub fn is_canceled(&self) -> bool

Source

pub fn acknowledge_cancel(&self) -> Result<(), Error>

Source

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.

Source§

impl<Rq, Rp> Responder<'_, Rq, Rp>
where Rp: Default,

Source

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

Source

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

Source

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.

Trait Implementations§

Source§

impl<Rq, Rp> Drop for Responder<'_, Rq, Rp>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'i, Rq, Rp> Freeze for Responder<'i, Rq, Rp>

§

impl<'i, Rq, Rp> !RefUnwindSafe for Responder<'i, Rq, Rp>

§

impl<'i, Rq, Rp> Send for Responder<'i, Rq, Rp>
where Rq: Send + Sync, Rp: Send + Sync,

§

impl<'i, Rq, Rp> Sync for Responder<'i, Rq, Rp>
where Rq: Send + Sync, Rp: Send + Sync,

§

impl<'i, Rq, Rp> Unpin for Responder<'i, Rq, Rp>

§

impl<'i, Rq, Rp> !UnwindSafe for Responder<'i, Rq, Rp>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.