Skip to main content

RouteState

Enum RouteState 

Source
pub enum RouteState<T> {
    NoSubRoute,
    SubRoute(T),
    ParseFailed {
        remaining_path: String,
        attempted_patterns: Vec<String>,
        closest_match: Option<ClosestMatch>,
    },
}
Expand description

路由状态枚举

用于替代 Option,提供更明确的路由解析状态信息 支持 serde 序列化/反序列化

Variants§

§

NoSubRoute

没有子路由(预期的叶子节点)

表示当前路由是一个叶子节点,不应该有子路由

§

SubRoute(T)

有子路由

表示成功解析到子路由

§

ParseFailed

解析失败

表示尝试解析子路由时失败,包含详细的调试信息

Fields

§remaining_path: String

剩余的路径

§attempted_patterns: Vec<String>

尝试匹配的模式列表

§closest_match: Option<ClosestMatch>

最接近的匹配信息(可选)

Implementations§

Source§

impl<T> RouteState<T>

RouteState 的实用方法实现

Source

pub fn no_sub_route() -> Self

创建一个没有子路由的状态

Source

pub fn sub_route(sub_router: T) -> Self

创建一个有子路由的状态

Source

pub fn parse_failed<S: Into<String>>( remaining_path: S, attempted_patterns: Vec<String>, closest_match: Option<ClosestMatch>, ) -> Self

创建一个解析失败的状态

Source

pub fn is_no_sub_route(&self) -> bool

检查是否没有子路由

Source

pub fn is_sub_route(&self) -> bool

检查是否有子路由

Source

pub fn is_parse_failed(&self) -> bool

检查是否解析失败

Source

pub fn as_sub_route(&self) -> Option<&T>

获取子路由的引用(如果存在)

Source

pub fn as_sub_route_mut(&mut self) -> Option<&mut T>

获取子路由的可变引用(如果存在)

Source

pub fn into_option(self) -> Option<T>

将 RouteState 转换为 Option(向后兼容)

Source

pub fn from_option(option: Option<T>) -> Self

从 Option 创建 RouteState(向后兼容)

Source

pub fn map<U, F>(self, f: F) -> RouteState<U>
where F: FnOnce(T) -> U,

映射子路由类型

Source

pub fn debug_info(&self) -> Option<RouteDebugInfo>

获取调试信息(如果是解析失败状态)

Trait Implementations§

Source§

impl<T: Clone> Clone for RouteState<T>

Source§

fn clone(&self) -> RouteState<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for RouteState<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: PartialEq> PartialEq for RouteState<T>

Source§

fn eq(&self, other: &RouteState<T>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: PartialEq> StructuralPartialEq for RouteState<T>

Auto Trait Implementations§

§

impl<T> Freeze for RouteState<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for RouteState<T>
where T: RefUnwindSafe,

§

impl<T> Send for RouteState<T>
where T: Send,

§

impl<T> Sync for RouteState<T>
where T: Sync,

§

impl<T> Unpin for RouteState<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for RouteState<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for RouteState<T>
where T: UnwindSafe,

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.