Struct reqchan::Responder
[−]
[src]
pub struct Responder<T> { /* fields omitted */ }
This end of the channel sends data in response to requests from
its Requester
.
Methods
impl<T> Responder<T>
[src]
fn try_respond(&self) -> Result<ResponseContract<T>, TryRespondError>
[src]
This method signals the intent of Responder
to respond to a request.
If successful, it returns a ResponseContract
to ensure the user sends
a datum.
Warning
Only one ResponseContract
may be active at a time.
Example
extern crate reqchan as chan; let (requester, responder) = chan::channel::<u32>(); // `requester` has not yet issued a request. match responder.try_respond() { Err(chan::TryRespondError::NoRequest) => { println!("There is no request!"); }, _ => unreachable!(), } let mut request_contract = requester.try_request().unwrap(); // `requester` has issued a request. let mut response_contract = responder.try_respond().unwrap(); // We cannot issue another response to the request. match responder.try_respond() { Err(chan::TryRespondError::Locked) => { println!("We cannot issue multiple responses to a request!"); }, _ => unreachable!(), } response_contract.send(8); println!("Number is {}", request_contract.try_receive().unwrap());