yew_router_nested_route_parser/
lib.rs

1//! Parser for yew-router's matcher syntax.
2//! This syntax allows specifying if a route should produce an enum variant or struct,
3//! and allows capturing sections from the route to be incorporated into its associated variant or struct.
4
5#![deny(
6    missing_docs,
7    missing_debug_implementations,
8    missing_copy_implementations,
9    trivial_casts,
10    trivial_numeric_casts,
11    unsafe_code,
12    unstable_features,
13    unused_qualifications
14)]
15
16mod core;
17mod error;
18pub mod parser;
19pub use crate::core::FieldNamingScheme;
20pub use error::{ParseError, PrettyParseError};
21mod optimizer;
22pub use optimizer::{convert_tokens, parse_str_and_optimize_tokens};
23use std::collections::HashMap;
24
25/// Alias of `HashMap<&'a str, String>` that represent strings captured from a route.
26///
27/// Captures contain keys corresponding to named match sections,
28/// and values containing the content captured by those sections.
29pub type Captures<'a> = HashMap<&'a str, String>;
30
31/// Tokens used to determine how to match and capture sections from a URL.
32#[derive(Debug, PartialEq, Clone)]
33pub enum MatcherToken {
34    /// Section-related tokens can be condensed into a match.
35    Exact(String),
36    /// Capture section.
37    Capture(CaptureVariant),
38    /// End token - if the string hasn't been consumed entirely, then the parse will fail.
39    /// This is useful for being able to specify more general matchers for variants that would
40    /// otherwise match above more specific variants.
41    End,
42}
43
44/// Variants that indicate how part of a string should be captured.
45#[derive(Debug, PartialEq, Clone)]
46pub enum CaptureVariant {
47    /// {}
48    Unnamed,
49    /// {*}
50    ManyUnnamed,
51    /// {5}
52    NumberedUnnamed {
53        /// Number of sections to match.
54        sections: usize,
55    },
56    /// {name} - captures a section and adds it to the map with a given name.
57    Named(String),
58    /// {*:name} - captures over many sections and adds it to the map with a given name.
59    ManyNamed(String),
60    /// {2:name} - captures a fixed number of sections with a given name.
61    NumberedNamed {
62        /// Number of sections to match.
63        sections: usize,
64        /// The key to be entered in the `Matches` map.
65        name: String,
66    },
67}