rocket/route/segment.rs
1use crate::http::RawStr;
2
3#[derive(Debug, Clone)]
4pub struct Segment {
5 pub value: String,
6 pub dynamic: bool,
7 pub trailing: bool,
8}
9
10impl Segment {
11 pub fn from(segment: &RawStr) -> Self {
12 let mut value = segment;
13 let mut dynamic = false;
14 let mut trailing = false;
15
16 if segment.starts_with('<') && segment.ends_with('>') {
17 dynamic = true;
18 value = &segment[1..(segment.len() - 1)];
19
20 if value.ends_with("..") {
21 trailing = true;
22 value = &value[..(value.len() - 2)];
23 }
24 }
25
26 Segment { value: value.to_string(), dynamic, trailing }
27 }
28}