pub trait Service<Sock>where
Sock: Socket,{
type MethodCall<'de>: Deserialize<'de> + Debug;
type ReplyParams<'ser>: Serialize + Debug
where Self: 'ser;
type ReplyStreamParams: Serialize + Debug;
type ReplyStream: Stream<Item = ReplyStreamItem<Self::ReplyStreamParams>> + Unpin;
type ReplyError<'ser>: Serialize + Debug
where Self: 'ser;
// Required method
fn handle<'ser>(
&'ser mut self,
method: &'ser Call<Self::MethodCall<'_>>,
conn: &mut Connection<Sock>,
fds: Vec<OwnedFd>,
) -> impl Future<Output = HandleResult<Self::ReplyParams<'ser>, Self::ReplyStream, Self::ReplyError<'ser>>>;
}Expand description
Service trait for handling method calls.
Instead of implementing this trait manually, prefer using the service attribute macro which
generates the implementation for you. The macro provides a more ergonomic API and handles the
boilerplate of method dispatching, error handling, and streaming replies.
See the service macro documentation for details and examples.
Required Associated Types§
Sourcetype MethodCall<'de>: Deserialize<'de> + Debug
type MethodCall<'de>: Deserialize<'de> + Debug
The type of method call that this service handles.
This should be a type that can deserialize itself from a complete method call message: i-e
an object containing method and parameter fields. This can be easily achieved using the
serde::Deserialize derive (See the code snippet in
crate::connection::WriteConnection::send_call documentation for an example).
Sourcetype ReplyParams<'ser>: Serialize + Debug
where
Self: 'ser
type ReplyParams<'ser>: Serialize + Debug where Self: 'ser
The type of the successful reply.
This should be a type that can serialize itself as the parameters field of the reply.
Sourcetype ReplyStreamParams: Serialize + Debug
type ReplyStreamParams: Serialize + Debug
The type of the item that Service::ReplyStream will be expected to yield.
This should be a type that can serialize itself as the parameters field of the reply.
Sourcetype ReplyStream: Stream<Item = ReplyStreamItem<Self::ReplyStreamParams>> + Unpin
type ReplyStream: Stream<Item = ReplyStreamItem<Self::ReplyStreamParams>> + Unpin
The type of the multi-reply stream.
If the client asks for multiple replies, this stream will be used to send them.
Sourcetype ReplyError<'ser>: Serialize + Debug
where
Self: 'ser
type ReplyError<'ser>: Serialize + Debug where Self: 'ser
The type of the error reply.
This should be a type that can serialize itself to the whole reply object, containing
error and parameter fields. This can be easily achieved using the serde::Serialize
derive (See the code snippet in crate::connection::ReadConnection::receive_reply
documentation for an example).
Required Methods§
Sourcefn handle<'ser>(
&'ser mut self,
method: &'ser Call<Self::MethodCall<'_>>,
conn: &mut Connection<Sock>,
fds: Vec<OwnedFd>,
) -> impl Future<Output = HandleResult<Self::ReplyParams<'ser>, Self::ReplyStream, Self::ReplyError<'ser>>>
fn handle<'ser>( &'ser mut self, method: &'ser Call<Self::MethodCall<'_>>, conn: &mut Connection<Sock>, fds: Vec<OwnedFd>, ) -> impl Future<Output = HandleResult<Self::ReplyParams<'ser>, Self::ReplyStream, Self::ReplyError<'ser>>>
Handle a method call.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.