Struct interchange::Requester
source · [−]pub struct Requester<I: 'static + Interchange> { /* private fields */ }
Expand description
Requesting end of the RPC interchange.
The owner of this end initiates RPC by sending a request.
It must then either wait until the responder end responds, upon which
it can send a new request again. It does so by periodically checking
whether take_response
is Some. Or it can attempt to cancel,
which the responder may or may not honour. For details, see the
cancel
method.
Implementations
sourceimpl<I: Interchange> Requester<I>
impl<I: Interchange> Requester<I>
sourcepub fn state(&self) -> State
pub fn state(&self) -> State
Current state of the interchange.
Informational only!
The responder may change this state between calls, internally atomics ensure correctness.
sourcepub fn request(&mut self, request: &I::REQUEST) -> Result<(), ()>
pub fn request(&mut self, request: &I::REQUEST) -> Result<(), ()>
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.
sourcepub fn cancel(&mut self) -> Result<Option<I::REQUEST>, ()>
pub fn cancel(&mut self) -> Result<Option<I::REQUEST>, ()>
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.
sourcepub fn response(&mut self) -> Option<&I::RESPONSE>
pub fn response(&mut self) -> Option<&I::RESPONSE>
Look for a response. If the responder has sent a response, we return it.
This may be called multiple times.
sourcepub fn take_response(&mut self) -> Option<I::RESPONSE>
pub fn take_response(&mut self) -> Option<I::RESPONSE>
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.
sourceimpl<I: Interchange> Requester<I> where
I::REQUEST: Default,
impl<I: Interchange> Requester<I> where
I::REQUEST: Default,
sourcepub fn request_mut(&mut self) -> Option<&mut I::REQUEST>
pub fn request_mut(&mut self) -> Option<&mut I::REQUEST>
If the interchange is idle, may build request into the returned value.
sourcepub fn send_request(&mut self) -> Result<(), ()>
pub fn send_request(&mut self) -> Result<(), ()>
Send a request that was already placed in the interchange using request_mut
.
Trait Implementations
impl<I: Interchange> Send for Requester<I>
Auto Trait Implementations
impl<I> !RefUnwindSafe for Requester<I>
impl<I> !Sync for Requester<I>
impl<I> Unpin for Requester<I>
impl<I> !UnwindSafe for Requester<I>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more