#[non_exhaustive]pub enum Match {
Found {
handler: BoxHandler,
params: Params,
},
MethodNotAllowed {
allow: Vec<Method>,
},
NotFound,
BadPath,
}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", &probe("/users/7")) {
Match::Found { params, .. } => assert_eq!(params.get("id").unwrap(), "7"),
_ => panic!("expected a match"),
}
assert!(matches!(router.route(&Method::GET, "/nope", &probe("/nope")), Match::NotFound));
assert!(matches!(router.route(&Method::POST, "/users/7", &probe("/users/7")), Match::MethodNotAllowed { .. }));Marked #[non_exhaustive]: a match on this enum outside churust-core
must carry a _ arm, so that a future routing outcome is not a breaking
change.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
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.
BadPath
A path segment could not be percent-decoded — a malformed escape or
bytes that are not valid UTF-8. The dispatcher turns this into
400 Bad Request.