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
#[derive(Serialize)]
pub struct Link {
#[serde(skip_serializing_if = "Option::is_none")]
class: Option<Vec<String>>,
href: String,
rel: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
title: Option<String>,
#[serde(skip_serializing_if = "Option::is_none", rename = "type")]
tpye: Option<String>,
}
impl Link {
pub fn new(rel: Vec<impl Into<String>>, href: impl Into<String>) -> Self {
Self {
class: None,
href: href.into(),
rel: rel.into_iter().map(|s| s.into()).collect(),
title: None,
tpye: None,
}
}
pub fn class(self, class: impl Into<String>) -> Self {
self.classes(vec![class])
}
pub fn classes(mut self, classes: Vec<impl Into<String>>) -> Self {
if let Some(ref mut s_class) = self.class {
for class in classes.into_iter() {
s_class.push(class.into());
}
} else {
let mut s_class = Vec::new();
for class in classes.into_iter() {
s_class.push(class.into());
}
self.class = Some(s_class)
}
self
}
pub fn title(mut self, title: impl Into<String>) -> Self {
self.title = Some(title.into());
self
}
pub fn tpye(mut self, tpye: impl Into<String>) -> Self {
self.tpye = Some(tpye.into());
self
}
}