Skip to main content

Service

Trait Service 

Source
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 ReplyStreamError: Serialize + Debug; type ReplyStream: Stream<Item = ReplyStreamItem<Self::ReplyStreamParams, Self::ReplyStreamError>> + 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§

Source

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).

Source

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.

Source

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.

Source

type ReplyStreamError: Serialize + Debug

The type of an error reply produced by a streaming method.

Unlike Self::ReplyError, this type cannot borrow from &self (the stream outlives the handle call). Services whose streaming methods never fail should set this to Infallible — the Err arm of ReplyStreamItem then becomes statically unreachable.

Source

type ReplyStream: Stream<Item = ReplyStreamItem<Self::ReplyStreamParams, Self::ReplyStreamError>> + Unpin

The type of the multi-reply stream.

If the client asks for multiple replies, this stream will be used to send them. Each stream item is either a success Reply or an error of type Self::ReplyStreamError.

Source

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).

Services whose methods never fail can use Infallible for this type as well.

Required Methods§

Source

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.

Implementors§