Trait strymon_communication::rpc::Request
[−]
[src]
pub trait Request<N: Name>: Serialize + DeserializeOwned { type Success: Serialize + DeserializeOwned; type Error: Serialize + DeserializeOwned; const NAME: N; }
A trait for defining the signature of a remote procedure.
Within this framework, a new request type can be defined by implementing
this trait. The type implementing Request
stores the arguments sent to
the remote receiver and then has to respond with either Ok(Request::Success)
or Err(Request::Error)
. In order for the receiver to be able to distinguish
the different incoming requests without fully decoding it, each request
type must define an associated constant Request::NAME
for this purpose.
Examples
ⓘThis example is not tested
#[derive(Serialize, Deserialize, Clone, Debug)] pub struct GetNamesForId { pub arg: u32, } #[derive(Serialize, Deserialize, Clone, Debug)] struct InvalidId; // CustomRPC is an enum implementing the `Name` trait impl Request<CustomRPC> for GetNamesForId { // A unique identifier for this method const NAME = CustomRPC::GetNamesForId; // Return type of a successful response type Success = Vec<String>; // Return type of a failed invocation type Error = InvalidId; }
Associated Types
type Success: Serialize + DeserializeOwned
The type of a successful response.
type Error: Serialize + DeserializeOwned
The type of a failed response.
Associated Constants
const NAME: N
A unique value identifying this type of request.