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
use crate::{
geocoding::error::Error,
geocoding::forward::ForwardRequest,
};
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
impl<'a> ForwardRequest<'a> {
pub fn build(&mut self) -> Result<&'a mut ForwardRequest, Error> {
if !self.validated { return Err(Error::RequestNotValidated) }
let mut query = format!(
"key={}",
self.client_settings.key
);
if let Some(address) = &self.address {
query.push_str("&address=");
query.push_str(&*utf8_percent_encode(&String::from(address), NON_ALPHANUMERIC).to_string())
}
if let Some(bounds) = &self.bounds {
query.push_str("&bounds=");
query.push_str(&*utf8_percent_encode(&String::from(bounds), NON_ALPHANUMERIC).to_string())
}
if let Some(components) = &self.components {
query.push_str("&components=");
query.push_str(&*utf8_percent_encode(
&String::from(components.iter().map(|component| String::from(component) + "|").collect::<String>().trim_end_matches('|')),
NON_ALPHANUMERIC
).to_string())
}
if let Some(language) = &self.language {
query.push_str("&language=");
query.push_str(&String::from(language))
}
if let Some(region) = &self.region {
query.push_str("®ion=");
query.push_str(&String::from(region))
}
self.query = Some(query);
Ok(self)
}
}