Skip to main content

BoxProcessorExt

Trait BoxProcessorExt 

Source
pub trait BoxProcessorExt {
    // Required method
    fn from_fn<F, Fut>(f: F) -> BoxProcessor
       where F: Fn(Exchange) -> Fut + Send + Sync + 'static,
             Fut: Future<Output = Result<Exchange, CamelError>> + Send + 'static;
}
Expand description

Extension trait for BoxProcessor providing ergonomic constructors.

Since BoxProcessor is a type alias for Tower’s BoxCloneService, we cannot add inherent methods to it. This trait fills that gap.

§Example

use camel_api::{BoxProcessor, BoxProcessorExt};

let processor = BoxProcessor::from_fn(|ex| Box::pin(async move { Ok(ex) }));

Required Methods§

Source

fn from_fn<F, Fut>(f: F) -> BoxProcessor
where F: Fn(Exchange) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<Exchange, CamelError>> + Send + 'static,

Create a BoxProcessor from an async closure.

This is a convenience shorthand for BoxProcessor::new(ProcessorFn::new(f)).

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§