rocket/route/
segment.rs

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
use crate::http::RawStr;

#[derive(Debug, Clone)]
pub struct Segment {
    pub value: String,
    pub dynamic: bool,
    pub trailing: bool,
}

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

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

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

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