Trait rmp_rpc::Service [−][src]
pub trait Service: Send { type RequestFuture: IntoStaticFuture<Item = Value, Error = Value>; fn handle_request(
&mut self,
method: &str,
params: &[Value]
) -> Self::RequestFuture; fn handle_notification(&mut self, method: &str, params: &[Value]); }
The Service
trait defines how a MessagePack-RPC
server handles requests and notifications.
Associated Types
type RequestFuture: IntoStaticFuture<Item = Value, Error = Value>
The type of future returned by handle_request
. This future will be spawned on the event
loop, and when it is complete then the result will be sent back to the client that made the
request.
Note that if your handle_request
method involves only a simple and quick computation,
then you can set RequestFut
to Result<Value, Value>
(which gets turned into a future
that completes immediately). You only need to use a "real" future if there's some longer
computation or I/O that needs to be deferred.
Required Methods
fn handle_request(
&mut self,
method: &str,
params: &[Value]
) -> Self::RequestFuture
&mut self,
method: &str,
params: &[Value]
) -> Self::RequestFuture
Handle a MessagePack-RPC
request.
The name of the request is method
, and the parameters are given in params
.
Note that this method is called synchronously within the main event loop, and so it should return quickly. If you need to run a longer computation, put it in a future and return it.
fn handle_notification(&mut self, method: &str, params: &[Value])
Handle a MessagePack-RPC
notification.
Note that this method is called synchronously within the main event loop, and so it should return quickly. If you need to run a longer computation, put it in a future and spawn it on the event loop.