forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp.rs
More file actions
54 lines (46 loc) · 1.09 KB
/
http.rs
File metadata and controls
54 lines (46 loc) · 1.09 KB
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
pub type ReqwestQuery = Vec<ReqwestQueryParam>;
pub type ReqwestQueryParam = (String, String);
/// URL Query component
#[derive(Default, Debug)]
pub struct Query {
params: Vec<QueryParam>,
}
impl Query {
pub fn empty() -> Self {
Self { params: vec![] }
}
pub fn params(params: Vec<QueryParam>) -> Self {
Self { params }
}
pub fn add_param(&mut self, param: QueryParam) {
self.params.push(param);
}
}
impl From<Query> for ReqwestQuery {
fn from(url_search_params: Query) -> Self {
url_search_params
.params
.iter()
.map(|param| ReqwestQueryParam::from((*param).clone()))
.collect()
}
}
/// URL query param
#[derive(Clone, Debug)]
pub struct QueryParam {
name: String,
value: String,
}
impl QueryParam {
pub fn new(name: &str, value: &str) -> Self {
Self {
name: name.to_string(),
value: value.to_string(),
}
}
}
impl From<QueryParam> for ReqwestQueryParam {
fn from(param: QueryParam) -> Self {
(param.name, param.value)
}
}