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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
use std::marker::PhantomData;
#[derive(Default, Serialize)]
pub struct ImageParams {
#[serde(rename = "filetype")]
pub file_type: Option<String>,
pub hidden: Option<bool>,
#[serde(rename = "type")]
pub kind: Option<String>,
pub nsfw: Option<bool>,
pub tags: Option<Vec<String>>,
#[serde(skip)]
phantom: PhantomData<()>,
}
impl ImageParams {
pub fn new(
file_type: Option<String>,
hidden: Option<bool>,
kind: Option<String>,
nsfw: Option<bool>,
tags: Option<Vec<String>>,
) -> Self {
Self {
phantom: PhantomData,
hidden,
file_type,
kind,
nsfw,
tags,
}
}
pub fn kind<S: Into<String>>(kind: S) -> Self {
Self {
kind: Some(kind.into()),
..Default::default()
}
}
pub fn tags<S: Into<String>>(tags: Vec<S>) -> Self {
Self {
tags: Some(tags.into_iter().map(|x| x.into()).collect()),
..Default::default()
}
}
pub(crate) fn into_data(self) -> Vec<(&'static str, String)> {
let mut data = vec![];
if let Some(file_type) = self.file_type {
data.push(("file_type", file_type));
}
if let Some(hidden) = self.hidden {
data.push(("hidden", if hidden { "true" } else { "false" }.to_owned()));
}
if let Some(kind) = self.kind {
data.push(("type", kind));
}
if let Some(nsfw) = self.nsfw {
data.push(("nsfw", if nsfw { "true" } else { "false" }.to_owned()));
}
if let Some(tags) = self.tags {
data.push(("tags", tags.join(",")));
}
data
}
}