pub struct Router<T> { /* private fields */ }
Expand description
A URL router.
See the crate documentation for details.
Implementations§
Source§impl<T> Router<T>
impl<T> Router<T>
Sourcepub fn insert(
&mut self,
route: impl Into<String>,
value: T,
) -> Result<(), InsertError>
pub fn insert( &mut self, route: impl Into<String>, value: T, ) -> Result<(), InsertError>
Insert a route.
§Examples
let mut router = Router::new();
router.insert("/home", "Welcome!")?;
router.insert("/users/:id", "A User")?;
Sourcepub fn at<'m, 'p>(
&'m self,
path: &'p str,
) -> Result<Match<'m, 'p, &'m T>, MatchError>
pub fn at<'m, 'p>( &'m self, path: &'p str, ) -> Result<Match<'m, 'p, &'m T>, MatchError>
Tries to find a value in the router matching the given path.
§Examples
let mut router = Router::new();
router.insert("/home", "Welcome!")?;
let matched = router.at("/home").unwrap();
assert_eq!(*matched.value, "Welcome!");
Sourcepub fn at_mut<'m, 'p>(
&'m mut self,
path: &'p str,
) -> Result<Match<'m, 'p, &'m mut T>, MatchError>
pub fn at_mut<'m, 'p>( &'m mut self, path: &'p str, ) -> Result<Match<'m, 'p, &'m mut T>, MatchError>
Tries to find a value in the router matching the given path, returning a mutable reference.
§Examples
let mut router = Router::new();
router.insert("/", 1)?;
*router.at_mut("/").unwrap().value += 1;
assert_eq!(*router.at("/").unwrap().value, 2);
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for Router<T>
impl<T> !RefUnwindSafe for Router<T>
impl<T> Send for Router<T>where
T: Send,
impl<T> Sync for Router<T>where
T: Sync,
impl<T> Unpin for Router<T>where
T: Unpin,
impl<T> UnwindSafe for Router<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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Layout§
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.