1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! A procedural macro crate for creating fast URI path routing functions.
use TokenStream;
use quote;
use parse_macro_input;
/// Create a routing function
///
/// ```
/// # use uri_path_router::route;
/// // Define a routing function with the following match-like syntax:
/// route! {
/// Route,
/// "foo" => {
/// "a" => FooA,
/// "b" => FooB,
/// },
/// "bar" => {
/// "a" => BarA,
/// x => Bar(x) {
/// "x" => X(x),
/// "y" => Y(x),
/// },
/// },
/// "baz" / "a" => {
/// "b" => Baz,
/// },
/// "long" / x / y / "z" => Long(x, y)
/// }
///
/// # fn main() {
/// // Inside a function you can match routes using:
/// assert_eq!(Route::try_from("/foo"), Err(()));
/// assert_eq!(Route::try_from("/foo/a"), Ok(Route::FooA));
/// assert_eq!(Route::try_from("/foo/a/b"), Err(()));
/// assert_eq!(Route::try_from("/foo/b"), Ok(Route::FooB));
/// assert_eq!(Route::try_from("/bar"), Err(()));
/// assert_eq!(Route::try_from("/bar/a"), Ok(Route::BarA));
/// assert_eq!(Route::try_from("/bar/whatever"), Ok(Route::Bar { x: "whatever" }));
/// assert_eq!(Route::try_from("/bar/whatever/"), Err(()));
/// assert_eq!(Route::try_from("/bar/baz/x"), Ok(Route::X { x: "baz" }));
/// assert_eq!(Route::try_from("/bar/baz/y"), Ok(Route::Y { x: "baz" }));
/// assert_eq!(Route::try_from("/baz/a/b"), Ok(Route::Baz));
/// assert_eq!(Route::try_from("/long/a/b/z"), Ok(Route::Long { x: "a", y: "b" }));
/// assert_eq!(Route::try_from("/wrong/b"), Err(()));
/// # }
///
/// ```