Struct interchange::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 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<'i, Rq, Rp> Responder<'i, 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<'i, Rq, Rp> Drop for Responder<'i, Rq, Rp>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

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

§

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

§

impl<'i, Rq, Rp> Sync for Responder<'i, Rq, Rp>where Rp: Send + Sync, Rq: 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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.