pub struct Router<T, U = ()> { /* private fields */ }Expand description
Resource router.
Maps paths to values of type T. Each resource can also have an optional
value of type U used by the recognize_*checked methods. Resources are
matched in registration order, the first matching resource wins.
Implementations§
Source§impl<T, U> Router<T, U>
impl<T, U> Router<T, U>
Sourcepub fn builder() -> RouterBuilder<T, U>
pub fn builder() -> RouterBuilder<T, U>
Creates a router builder.
Sourcepub fn recognize<R, P>(&self, resource: &mut R) -> Option<(&T, ResourceId)>where
R: Resource<P>,
P: ResourcePath,
pub fn recognize<R, P>(&self, resource: &mut R) -> Option<(&T, ResourceId)>where
R: Resource<P>,
P: ResourcePath,
Finds the first resource that matches the path.
On a match, the values of dynamic segments are stored in resource,
and a prefix match skips the matched part of the path.
Sourcepub fn recognize_mut<R, P>(
&mut self,
resource: &mut R,
) -> Option<(&mut T, ResourceId)>where
R: Resource<P>,
P: ResourcePath,
pub fn recognize_mut<R, P>(
&mut self,
resource: &mut R,
) -> Option<(&mut T, ResourceId)>where
R: Resource<P>,
P: ResourcePath,
Same as recognize(), returns a mutable reference.
Sourcepub fn recognize_checked<R, P, F>(
&self,
resource: &mut R,
check: F,
) -> Option<(&T, ResourceId)>
pub fn recognize_checked<R, P, F>( &self, resource: &mut R, check: F, ) -> Option<(&T, ResourceId)>
Finds the first resource that matches the path and passes check.
check is called for each matching resource with the resource and the
resource’s optional value of type U.
Sourcepub fn recognize_checked_mut<R, P, F>(
&mut self,
resource: &mut R,
check: F,
) -> Option<(&mut T, ResourceId)>
pub fn recognize_checked_mut<R, P, F>( &mut self, resource: &mut R, check: F, ) -> Option<(&mut T, ResourceId)>
Same as recognize_checked(), returns a
mutable reference.
Trait Implementations§
Auto Trait Implementations§
impl<T, U> Freeze for Router<T, U>
impl<T, U> RefUnwindSafe for Router<T, U>where
T: RefUnwindSafe,
U: RefUnwindSafe,
impl<T, U> Send for Router<T, U>
impl<T, U> Sync for Router<T, U>
impl<T, U> Unpin for Router<T, U>
impl<T, U> UnsafeUnpin for Router<T, U>
impl<T, U> UnwindSafe for Router<T, U>where
T: UnwindSafe,
U: 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