smarty_rust_sdk/international_street_api/
lookup.rs1use crate::international_street_api::candidate::Candidate;
2use crate::sdk::has_param;
3use std::fmt::{Display, Formatter};
4
5#[derive(Clone, Debug, PartialEq)]
6pub struct Lookup {
7 pub input_id: String,
8 pub country: String,
9 pub geocode: bool,
10 pub language: Language,
11 pub freeform: String,
12 pub address1: String,
13 pub address2: String,
14 pub address3: String,
15 pub address4: String,
16 pub organization: String,
17 pub locality: String,
18 pub administrative_area: String,
19 pub postal_code: String,
20 pub features: String,
21
22 pub results: Vec<Candidate>,
23}
24
25impl Default for Lookup {
26 fn default() -> Self {
27 Lookup {
28 input_id: String::default(),
29 country: String::default(),
30 geocode: true,
31 language: Language::Native,
32 freeform: String::default(),
33 address1: String::default(),
34 address2: String::default(),
35 address3: String::default(),
36 address4: String::default(),
37 organization: String::default(),
38 locality: String::default(),
39 administrative_area: String::default(),
40 postal_code: String::default(),
41 features: String::default(),
42 results: vec![],
43 }
44 }
45}
46
47impl Lookup {
48 pub(crate) fn into_param_array(self) -> Vec<(String, String)> {
49 vec![
50 has_param("input_id".to_string(), self.input_id),
51 has_param("country".to_string(), self.country),
52 Some(("geocode".to_string(), self.geocode.to_string())),
53 has_param("language".to_string(), self.language.to_string()),
54 has_param("address1".to_string(), self.address1),
55 has_param("address2".to_string(), self.address2),
56 has_param("address3".to_string(), self.address3),
57 has_param("address4".to_string(), self.address4),
58 has_param("organization".to_string(), self.organization),
59 has_param("locality".to_string(), self.locality),
60 has_param("administrative_area".to_string(), self.administrative_area),
61 has_param("postal_code".to_string(), self.postal_code),
62 has_param("features".to_string(), self.features),
63 ]
64 .iter()
65 .filter_map(Option::clone)
66 .collect::<Vec<_>>()
67 }
68}
69
70#[derive(Clone, Debug, PartialEq)]
71pub enum Language {
72 Native,
73 Latin,
74}
75
76impl Display for Language {
77 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
78 match self {
79 Language::Native => write!(f, "native"),
80 Language::Latin => write!(f, "latin"),
81 }
82 }
83}