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 function In → Out that processes inputs.
This trait is the foundation for building composable services.
Implement it directly for custom services, or use Execute
to wrap closures.
See the crate documentation for usage examples and layer composition.
Required Associated Types§
Required Methods§
Sourcefn execute(&self, input: In) -> impl Future<Output = Self::Out> + Send
fn execute(&self, input: In) -> impl Future<Output = Self::Out> + Send
Processes the input and returns the output.
The returned future must be Send for compatibility with multi-threaded
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", so this trait is not object safe.
Implementations on Foreign Types§
Implementors§
Source§impl<In: Send, Out, S> Service<In> for Intercept<In, Out, S>where
S: Service<In, Out = Out>,
Available on crate features intercept only.
impl<In: Send, Out, S> Service<In> for Intercept<In, Out, S>where
S: Service<In, Out = Out>,
Available on crate features
intercept only.