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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use std::fmt;
use std::cmp;
use Method;
use Handler;
use context::MaybeUtf8Slice;
#[derive(Clone,)]
pub struct Link<'a> {
pub method: Option<Method>,
pub path: Vec<LinkSegment<'a>>,
pub handler: Option<&'a Handler>,
}
impl<'a> fmt::Debug for Link<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "method: {:?}, path: {:?}, handler present: {}", self.method, self.path, self.handler.is_some())
}
}
impl<'a> cmp::PartialEq for Link<'a> {
fn eq(&self, other: &Link<'a>) -> bool {
self.method == other.method && self.path == other.path
}
}
impl<'a> cmp::Eq for Link<'a> {}
impl<'a> cmp::PartialOrd for Link<'a> {
fn partial_cmp(&self, other: &Link<'a>) -> Option<cmp::Ordering> {
Some(self.cmp(other))
}
}
impl<'a> cmp::Ord for Link<'a> {
fn cmp(&self, other: &Link<'a>) -> cmp::Ordering {
let method_ord = match (&self.method, &other.method) {
(&None, &None) => cmp::Ordering::Equal,
(&Some(_), &None) => cmp::Ordering::Greater,
(&None, &Some(_)) => cmp::Ordering::Less,
(&Some(ref this_method), &Some(ref other_method)) => this_method.as_ref().cmp(&other_method.as_ref()),
};
if method_ord == cmp::Ordering::Equal {
self.path.cmp(&other.path)
} else {
method_ord
}
}
}
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
pub struct LinkSegment<'a> {
pub label: MaybeUtf8Slice<'a>,
pub ty: SegmentType
}
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
pub enum SegmentType {
Static,
VariableSegment,
VariableSequence,
}