pub trait Requestable {
type Key: PartialEq + Eq + Hash + Send + Clone;
// Required methods
fn req_id(&self) -> Option<Self::Key>;
fn to(&self) -> Option<Self::Key>;
// Provided methods
fn is_request(&self) -> bool { ... }
fn is_response(&self) -> bool { ... }
}
Expand description
Responses transmitted over an AsyncConnection can be matched
with their request by looking for messages where m1.req_id() == m2.to()
.
Higher level implementors over AsyncConnection can use any method
to generate ID’s of any type that implements Eq + Hash.
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn is_request(&self) -> bool
fn is_request(&self) -> bool
If the message has a request ID, it is a request. It is possible for a response to simultaneously be a request.
Sourcefn is_response(&self) -> bool
fn is_response(&self) -> bool
If the message has a response ID, it is a response. It is possible for a response to simultaneously be a request.
Implementors§
Source§impl Requestable for ZeroMessage
use zeronet_protocol::message::ZeroMessage;
use zeronet_protocol::requestable::Requestable;
let request = ZeroMessage::request("handshake", 0, "body".to_string());
assert!(request.is_request());
assert!(!request.is_response());
let response = ZeroMessage::response(0, "body".to_string());
assert!(response.is_response());
assert!(!response.is_request());
impl Requestable for ZeroMessage
use zeronet_protocol::message::ZeroMessage;
use zeronet_protocol::requestable::Requestable;
let request = ZeroMessage::request("handshake", 0, "body".to_string());
assert!(request.is_request());
assert!(!request.is_response());
let response = ZeroMessage::response(0, "body".to_string());
assert!(response.is_response());
assert!(!response.is_request());