pub enum Match {
Found {
handler: BoxHandler,
params: HashMap<String, String>,
},
MethodNotAllowed {
allow: Vec<Method>,
},
NotFound,
}Expand description
The outcome of routing a (method, path) pair against the Router.
Returned by Router::route. The framework translates each variant into a
response: Found runs the handler,
MethodNotAllowed yields 405 with an Allow
header, and NotFound yields 404.
use churust_core::{boxed, Call, IntoHandler, Router, Match};
use http::Method;
let mut router = Router::new();
router.add(Method::GET, "/users/{id}", boxed((|_c: Call| async { "ok" }).into_handler()));
match router.route(&Method::GET, "/users/7") {
Match::Found { params, .. } => assert_eq!(params.get("id").unwrap(), "7"),
_ => panic!("expected a match"),
}
assert!(matches!(router.route(&Method::GET, "/nope"), Match::NotFound));
assert!(matches!(router.route(&Method::POST, "/users/7"), Match::MethodNotAllowed { .. }));Variants§
Found
A handler matched the path and method. Carries the matched handler and
the captured path parameters ({name} -> value).
Fields
§
handler: BoxHandlerThe handler registered for this (path, method).
MethodNotAllowed
The path matched a route, but not for this method. allow lists the
methods that are registered (used to build the Allow header).
NotFound
No route matched the path at all.
Auto Trait Implementations§
impl !RefUnwindSafe for Match
impl !UnwindSafe for Match
impl Freeze for Match
impl Send for Match
impl Sync for Match
impl Unpin for Match
impl UnsafeUnpin for Match
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