Crates.io | route_match_macros |
lib.rs | route_match_macros |
version | 0.2.0 |
source | src |
created_at | 2024-08-23 19:35:35.532374 |
updated_at | 2024-08-23 19:53:23.613615 |
description | The route_match macro implementation |
homepage | |
repository | https://github.com/spencerkohan/route_match/tree/main/route_match_macro |
max_upload_size | |
id | 1349555 |
size | 14,960 |
This is a procedural macro for implementing routing in hyper.
route! {
match request {
GET /foo/bar => get_fubar(request)
POST /foo/:id => post_foo(request, id)
}
}
This expands to:
{
let method = request.method.clone();
let path: Vec<&str> = request.path.clone().split('/').collect();
if let Some(()) = {
if &method != &http::Method::GET {
None
} else if path.len() != PATH_LENGTH {
None
} else if path[0] != "foo" || path[1] != "bar" {
None
} else {
Some(())
}
} {
get_fubar(request)
} else if let Some(id) = {
if &method != &http::Method::POST {
None
} else if path.len() != PATH_LENGTH {
None
} else if path[0] != "foo" {
None
} else {
let id = path[1];
Some(id)
}
} {
post_foo(request, id)
}
}