A rust crate for writying your web routes declaratively, and then parsing and formatting urls.

For instructions for the proc macro, see the documentation for rooty_derive::Routes.

The trait adds some minimal wrapping around parsing and formatting, in case you want to implement Display and FromStr differently for your Routes type.

Examples

Full example

```rust use chrono::NaiveDate; use rooty::{NotFound, Routes}; use std::str::FromStr;

[derive(Debug, Routes)]

pub enum MyRoutes { #[route = "/"] Home, #[route = "/about"] About, #[route = "/users/{id}"] User { id: i32 }, #[route = "/posts/{date}"] Posts { date: NaiveDate }, #[route = "/post/{title}"] Post { title: String }, }

fn main() { asserteq!(MyRoutes::Home.url().tostring(), "/"); asserteq!(MyRoutes::About.url().tostring(), "/about"); asserteq!(MyRoutes::User { id: 32 }.url().tostring(), "/users/32"); asserteq!( MyRoutes::Posts { date: NaiveDate::fromstr("2018-12-11").unwrap() } .url().tostring(), "/posts/2018-12-11" ); asserteq!( MyRoutes::Post { title: "myposttitle".into() } .url().tostring(), "/post/myposttitle" ); println!("{:?}", MyRoutes::parseurl("/post/mypost")); println!("{:?}", MyRoutes::parseurl("/posts/2012-12-07")); assert!(MyRoutes::parseurl("/a/made/up/url").iserr()); } ```