pub struct Router<T> { /* private fields */ }
Expand description
A URL router.
See the crate documentation for details.
Implementations
sourceimpl<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> !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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more