Skip to main content

Service

Trait Service 

Source
pub trait Service<In>: Send + Sync {
    type Out;

    // Required method
    fn execute(&self, input: In) -> impl Future<Output = Self::Out> + Send;
}
Expand description

An async operation from In to Out.

Implement this trait for a custom service. Use Execute to wrap a function or closure.

See the crate documentation for examples and layer composition.

Required Associated Types§

Source

type Out

The service output.

Required Methods§

Source

fn execute(&self, input: In) -> impl Future<Output = Self::Out> + Send

Processes an input and returns an output.

The returned future must implement Send for use on multithreaded async runtimes.

§Examples
use layered::Service;

struct EchoService;

impl Service<String> for EchoService {
    type Out = String;

    async fn execute(&self, input: String) -> Self::Out {
        input
    }
}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<S, In> Service<In> for Arc<S>
where S: Service<In>,

Source§

type Out = <S as Service<In>>::Out

Source§

fn execute( &self, input: In, ) -> impl Future<Output = <Arc<S> as Service<In>>::Out> + Send

Source§

impl<S, In> Service<In> for Box<S>
where S: Service<In>,

Source§

type Out = <S as Service<In>>::Out

Source§

fn execute( &self, input: In, ) -> impl Future<Output = <Box<S> as Service<In>>::Out> + Send

Implementors§

Source§

impl<E, F, In, Out> Service<In> for Execute<E>
where E: Fn(In) -> F + Send + Sync, F: Future<Output = Out> + Send,

Source§

type Out = Out