pub trait Operator<UpIn: PipelineIO, UpOut: PipelineIO, DownIn: PipelineIO, DownOut: PipelineIO>: Data {
// Required method
fn generate<'life0, 'async_trait>(
&'life0 self,
req: UpIn,
next: Arc<dyn AsyncEngine<DownIn, DownOut, Error>>,
) -> Pin<Box<dyn Future<Output = Result<UpOut, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
// Provided method
fn into_operator(
self: &Arc<Self>,
) -> Arc<PipelineOperator<UpIn, UpOut, DownIn, DownOut>>
where Self: Sized { ... }
}
Expand description
An Operator
is a trait that defines the behavior of how two AsyncEngine
can be chained together.
An Operator
is not quite an AsyncEngine
because its generate method requires both the upstream
request, but also the downstream AsyncEngine
to which it will pass the transformed request.
The Operator
logic must transform the upstream request UpIn
to the downstream request DownIn
,
then transform the downstream response DownOut
to the upstream response UpOut
.
A PipelineOperator
accepts an Operator
and presents itself as an AsyncEngine
for the upstream
AsyncEngine<UpIn, UpOut, Error>
.
§Example of type transformation and data flow
... --> <UpIn> ---> [Operator] --> <DownIn> ---> ...
... <-- <UpOut> --> [Operator] <-- <DownOut> <-- ...
Required Methods§
Sourcefn generate<'life0, 'async_trait>(
&'life0 self,
req: UpIn,
next: Arc<dyn AsyncEngine<DownIn, DownOut, Error>>,
) -> Pin<Box<dyn Future<Output = Result<UpOut, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn generate<'life0, 'async_trait>(
&'life0 self,
req: UpIn,
next: Arc<dyn AsyncEngine<DownIn, DownOut, Error>>,
) -> Pin<Box<dyn Future<Output = Result<UpOut, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
This method is expected to transform the upstream request UpIn
to the downstream request DownIn
,
call the next AsyncEngine
with the transformed request, then transform the downstream response
DownOut
to the upstream response UpOut
.