Struct strymon_communication::rpc::RequestBuf
[−]
[src]
pub struct RequestBuf<N: Name> { /* fields omitted */ }
Receiver-side buffer containing an incoming request.
This type represents a request to be processed by a receiver. In order to
serve a request, the receiver code needs to identify the method by calling
name()
, decode it using decode()
,
process it and respond using the obtained Responder
.
Examples:
Requests are received on the Incoming
queue and
are then typically decoded using a match
statement as follows:
ⓘThis example is not tested
fn dispatch(&mut self, request: RequestBuf) -> io::Result<()> { match request.name() { &CustomRPC::Foo => { let (args, responder) = request.decode::<Foo>()?; let result = self.foo(args); responder.respond(result); }, &CustomRPC::Bar => { // handle requests of type `Bar`… }, }; Ok(()) }
Methods
impl<N: Name> RequestBuf<N>
[src]
pub fn name(&self) -> &N
[src]
Extracting the Request::NAME
to identfy the request type.
pub fn decode<R: Request<N>>(self) -> Result<(R, Responder<N, R>)>
[src]
Decodes the request into the request data and a responder handle.
The returned Responder
handle is to be used
to serve the decoded request R
.