Skip to main content

MiddlewareChain

Struct MiddlewareChain 

Source
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>

Source

pub fn new(layers: Vec<&'m dyn Middleware>) -> Self

Build a chain. The first layer is outermost.

Source

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.

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V