route_match_macros

Crates.ioroute_match_macros
lib.rsroute_match_macros
version
sourcesrc
created_at2024-08-23 19:35:35.532374
updated_at2024-11-18 21:25:29.946098
descriptionThe route_match macro implementation
homepage
repositoryhttps://github.com/spencerkohan/route_match/tree/main/route_match_macro
max_upload_size
id1349555
Cargo.toml error:TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Spencer Kohan (spencerkohan)

documentation

https://docs.rs/route_match_macros

README

Route Macros

This is a procedural macro for implementing routing in hyper.

Usage


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)
      }

  }

Commit count: 14

cargo fmt