Struct interchange::Requester

source ·
pub struct Requester<'i, Rq, Rp> { /* private fields */ }
Expand description

Requester end of a channel

For a static Channel or Interchange, the requester uses a 'static lifetime parameter

Implementations§

source§

impl<'i, Rq, Rp> Requester<'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 request(&mut self, request: Rq) -> Result<(), Error>

Send a request to the responder.

If efficiency is a concern, or requests need multiple steps to construct, use request_mut and `send_request.

If the RPC state is Idle, this always succeeds, else calling is a logic error and the request is returned.

source

pub fn cancel(&mut self) -> Result<Option<Rq>, Error>

Attempt to cancel a request.

If the responder has not taken the request yet, this succeeds and returns the request.

If the responder has taken the request (is processing), we succeed and return None.

In other cases (Idle or Reponsed) there is nothing to cancel and we fail.

source

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

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

This may be called multiple times.

source

pub fn with_response<R>(&self, f: impl FnOnce(&Rp) -> R) -> Result<R, Error>

If there is a request waiting, perform an operation with a reference to it

This may be called multiple times.

source

pub fn take_response(&mut self) -> Option<Rp>

Look for a response. If the responder has sent a response, we return it.

This may be called only once as it move the state to Idle. If you need copies, clone the request.

source§

impl<'i, Rq, Rp> Requester<'i, Rq, Rp>where Rq: Default,

source

pub fn with_request_mut<R>( &mut self, f: impl FnOnce(&mut Rq) -> R ) -> Result<R, Error>

Initialize a request with its default values and mutates it with f

This is usefull to build large structures in-place

source

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

Initialize a request 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_request(&mut self) -> Result<(), Error>

Send a request that was already placed in the channel using request_mut or with_request_mut.

Trait Implementations§

source§

impl<'i, Rq, Rp> Drop for Requester<'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 Requester<'i, Rq, Rp>

§

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

§

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

§

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

§

impl<'i, Rq, Rp> !UnwindSafe for Requester<'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.