pub enum RouteState<T> {
NoSubRoute,
SubRoute(T),
ParseFailed {
remaining_path: String,
attempted_patterns: Vec<String>,
closest_match: Option<ClosestMatch>,
},
}Expand description
路由状态枚举
用于替代 Option
Variants§
NoSubRoute
没有子路由(预期的叶子节点)
表示当前路由是一个叶子节点,不应该有子路由
SubRoute(T)
有子路由
表示成功解析到子路由
ParseFailed
解析失败
表示尝试解析子路由时失败,包含详细的调试信息
Implementations§
Source§impl<T> RouteState<T>
RouteState 的实用方法实现
impl<T> RouteState<T>
RouteState 的实用方法实现
Sourcepub fn no_sub_route() -> Self
pub fn no_sub_route() -> Self
创建一个没有子路由的状态
Sourcepub fn parse_failed<S: Into<String>>(
remaining_path: S,
attempted_patterns: Vec<String>,
closest_match: Option<ClosestMatch>,
) -> Self
pub fn parse_failed<S: Into<String>>( remaining_path: S, attempted_patterns: Vec<String>, closest_match: Option<ClosestMatch>, ) -> Self
创建一个解析失败的状态
Sourcepub fn is_no_sub_route(&self) -> bool
pub fn is_no_sub_route(&self) -> bool
检查是否没有子路由
Sourcepub fn is_sub_route(&self) -> bool
pub fn is_sub_route(&self) -> bool
检查是否有子路由
Sourcepub fn is_parse_failed(&self) -> bool
pub fn is_parse_failed(&self) -> bool
检查是否解析失败
Sourcepub fn as_sub_route(&self) -> Option<&T>
pub fn as_sub_route(&self) -> Option<&T>
获取子路由的引用(如果存在)
Sourcepub fn as_sub_route_mut(&mut self) -> Option<&mut T>
pub fn as_sub_route_mut(&mut self) -> Option<&mut T>
获取子路由的可变引用(如果存在)
Sourcepub fn into_option(self) -> Option<T>
pub fn into_option(self) -> Option<T>
将 RouteState 转换为 Option(向后兼容)
Sourcepub fn from_option(option: Option<T>) -> Self
pub fn from_option(option: Option<T>) -> Self
从 Option 创建 RouteState(向后兼容)
Sourcepub fn map<U, F>(self, f: F) -> RouteState<U>where
F: FnOnce(T) -> U,
pub fn map<U, F>(self, f: F) -> RouteState<U>where
F: FnOnce(T) -> U,
映射子路由类型
Sourcepub fn debug_info(&self) -> Option<RouteDebugInfo>
pub fn debug_info(&self) -> Option<RouteDebugInfo>
获取调试信息(如果是解析失败状态)
Trait Implementations§
Source§impl<T: Clone> Clone for RouteState<T>
impl<T: Clone> Clone for RouteState<T>
Source§fn clone(&self) -> RouteState<T>
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: Debug> Debug for RouteState<T>
impl<T: Debug> Debug for RouteState<T>
Source§impl<T: PartialEq> PartialEq for RouteState<T>
impl<T: PartialEq> PartialEq for RouteState<T>
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> 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