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
#[derive(Debug, Clone)]
pub struct Segment {
    /// The name of the parameter or just the static string.
    pub value: String,
    /// This is a `<a>`.
    pub dynamic: bool,
    /// This is a `<a..>`.
    pub dynamic_trail: bool,
}

impl Segment {
    pub fn from(segment: &crate::http::RawStr) -> Self {
        let mut value = segment;
        let mut dynamic = false;
        let mut dynamic_trail = false;

        if segment.starts_with('<') && segment.ends_with('>') {
            dynamic = true;
            value = &segment[1..(segment.len() - 1)];

            if value.ends_with("..") {
                dynamic_trail = true;
                value = &value[..(value.len() - 2)];
            }
        }

        Segment { value: value.to_string(), dynamic, dynamic_trail }
    }
}