pub struct MiddlewareChain { /* private fields */ }Expand description
中间件链 — 定义中间件执行顺序
业务期望顺序:order() 数组首元素最先执行。
调用方在 ServiceBuilder 上注册时需逆序调用 layer()(后注册先执行)。
Implementations§
Source§impl MiddlewareChain
impl MiddlewareChain
Sourcepub fn default_chain() -> Self
pub fn default_chain() -> Self
创建默认链(使用 DEFAULT_ORDER)
Sourcepub fn php_global() -> Self
pub fn php_global() -> Self
创建 PHP 全局链(使用 PHP_GLOBAL_ORDER,对齐 app/middleware.php)
Sourcepub fn push(self, kind: MiddlewareKind) -> Self
pub fn push(self, kind: MiddlewareKind) -> Self
追加一个中间件到链尾(最后执行)
Sourcepub fn insert(self, index: usize, kind: MiddlewareKind) -> Result<Self, String>
pub fn insert(self, index: usize, kind: MiddlewareKind) -> Result<Self, String>
在指定位置插入中间件
返回 Err(message) 如果位置越界。
Sourcepub fn remove(&mut self, index: usize) -> Option<MiddlewareKind>
pub fn remove(&mut self, index: usize) -> Option<MiddlewareKind>
移除并返回指定位置的中间件
返回 None 如果位置越界。
Sourcepub fn remove_kind(&mut self, kind: MiddlewareKind) -> usize
pub fn remove_kind(&mut self, kind: MiddlewareKind) -> usize
移除所有指定类型的中间件
返回被移除的数量。
Sourcepub fn remove_from(&mut self, kind: MiddlewareKind) -> usize
pub fn remove_from(&mut self, kind: MiddlewareKind) -> usize
移除指定类型之后的所有中间件(含指定类型)
用于「公开 API 跳过 Auth 及之后中间件」场景。
返回被移除的数量;若 kind 不存在则不移除任何中间件,返回 0。
Sourcepub fn order(&self) -> &[MiddlewareKind]
pub fn order(&self) -> &[MiddlewareKind]
返回中间件顺序(业务期望顺序,首元素最先执行)
Sourcepub fn service_builder_order(&self) -> Vec<MiddlewareKind>
pub fn service_builder_order(&self) -> Vec<MiddlewareKind>
返回 ServiceBuilder 注册顺序(业务期望顺序的逆序)
ServiceBuilder::layer 是「后注册先执行」,因此注册时需逆序。
调用方按此顺序调用 ServiceBuilder::layer(layer_xxx) 即可保证
业务期望顺序与实际执行顺序一致。
Sourcepub fn contains(&self, kind: MiddlewareKind) -> bool
pub fn contains(&self, kind: MiddlewareKind) -> bool
是否包含指定中间件
Sourcepub fn position(&self, kind: MiddlewareKind) -> Option<usize>
pub fn position(&self, kind: MiddlewareKind) -> Option<usize>
返回指定中间件的位置(首次出现)
Sourcepub fn has_duplicates(&self) -> bool
pub fn has_duplicates(&self) -> bool
校验链中无重复中间件
重复中间件通常表示配置错误(如 Auth 注册两次),应避免。
Trait Implementations§
Source§impl Clone for MiddlewareChain
impl Clone for MiddlewareChain
Source§fn clone(&self) -> MiddlewareChain
fn clone(&self) -> MiddlewareChain
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MiddlewareChain
impl Debug for MiddlewareChain
Source§impl Default for MiddlewareChain
impl Default for MiddlewareChain
Source§impl Display for MiddlewareChain
impl Display for MiddlewareChain
impl Eq for MiddlewareChain
Source§impl PartialEq for MiddlewareChain
impl PartialEq for MiddlewareChain
impl StructuralPartialEq for MiddlewareChain
Auto Trait Implementations§
impl Freeze for MiddlewareChain
impl RefUnwindSafe for MiddlewareChain
impl Send for MiddlewareChain
impl Sync for MiddlewareChain
impl Unpin for MiddlewareChain
impl UnsafeUnpin for MiddlewareChain
impl UnwindSafe for MiddlewareChain
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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 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>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.