pub struct MiddlewareChain<'m> { /* private fields */ }Expand description
A nest of middlewares around a model: [a, b] runs a(b(model)).
Implementations§
Source§impl<'m> MiddlewareChain<'m>
impl<'m> MiddlewareChain<'m>
Sourcepub fn new(layers: Vec<&'m dyn Middleware>) -> Self
pub fn new(layers: Vec<&'m dyn Middleware>) -> Self
Build a chain. The first layer is outermost.
Sourcepub fn generate(
&self,
params: Params,
model: &dyn Model,
) -> Result<String, MiddlewareError>
pub fn generate( &self, params: Params, model: &dyn Model, ) -> Result<String, MiddlewareError>
Drive the unary path: transform params front-to-back, then wrap the model generation through the onion.
§Errors
Propagates the first MiddlewareError from any layer or the model.
Sourcepub fn stream(
&self,
params: Params,
model: &dyn StreamModel,
) -> Result<Vec<String>, MiddlewareError>
pub fn stream( &self, params: Params, model: &dyn StreamModel, ) -> Result<Vec<String>, MiddlewareError>
Drive the streaming path: transform params front-to-back, then unwind the
response stream through the onion, innermost layer first. Each layer’s
Middleware::wrap_stream consumes the chunks the next-inner layer
emitted; the outermost layer’s emissions are collected and returned.
Between two layers the inner layer’s emitted chunks are buffered before the outer layer consumes them. A single-guardrail chain — the real case — has no inter-layer buffer and streams end-to-end; the guardrail’s own hold-back is exercised regardless.
§Errors
Propagates the first MiddlewareError from any layer or the model.
Auto Trait Implementations§
impl<'m> !RefUnwindSafe for MiddlewareChain<'m>
impl<'m> !UnwindSafe for MiddlewareChain<'m>
impl<'m> Freeze for MiddlewareChain<'m>
impl<'m> Send for MiddlewareChain<'m>
impl<'m> Sync for MiddlewareChain<'m>
impl<'m> Unpin for MiddlewareChain<'m>
impl<'m> UnsafeUnpin for MiddlewareChain<'m>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more