smarty_rust_sdk/us_extract_api/
lookup.rs1use crate::sdk::has_param;
2use crate::us_extract_api::extraction::ExtractionResult;
3use crate::us_street_api::lookup::MatchStrategy;
4use serde::Serialize;
5use std::fmt::{Display, Formatter};
6
7#[derive(Debug, Clone, PartialEq, Serialize)]
8pub struct Lookup {
9 pub text: String,
10 pub html: HTMLPayload,
11 pub aggressive: bool,
12 #[serde(rename = "addr_line_breaks")]
13 pub addresses_with_line_breaks: bool, #[serde(rename = "addr_per_line")]
15 pub addresses_per_line: i32, #[serde(rename = "match")]
17 pub match_strategy: MatchStrategy,
18 #[serde(skip_serializing)]
19 pub result: ExtractionResult,
20}
21
22impl Default for Lookup {
23 fn default() -> Self {
24 Lookup {
25 text: String::default(),
26 html: HTMLPayload::HTMLUnspecified,
27 aggressive: false,
28 addresses_with_line_breaks: false,
29 addresses_per_line: 1,
30 match_strategy: MatchStrategy::Strict,
31 result: ExtractionResult::default(),
32 }
33 }
34}
35
36impl Lookup {
37 pub(crate) fn into_param_array(self) -> Vec<(String, String)> {
38 vec![
39 has_param("html".to_string(), self.html.to_string()),
40 has_param("aggressive".to_string(), self.aggressive),
41 has_param(
42 "addr_line_breaks".to_string(),
43 self.addresses_with_line_breaks,
44 ),
45 has_param("addr_per_line".to_string(), self.addresses_per_line),
46 has_param("match".to_string(), self.match_strategy.to_string()),
47 ]
48 .iter()
49 .filter_map(Option::clone)
50 .collect::<Vec<_>>()
51 }
52}
53
54#[derive(Debug, Clone, PartialEq, Serialize)]
55pub enum HTMLPayload {
56 #[serde(rename = "")]
57 HTMLUnspecified,
58 #[serde(rename = "true")]
59 HTMLYes,
60 #[serde(rename = "false")]
61 HTMLNo,
62}
63impl Display for HTMLPayload {
64 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
65 match self {
66 HTMLPayload::HTMLUnspecified => {
67 write!(f, "")
68 }
69 HTMLPayload::HTMLYes => {
70 write!(f, "true")
71 }
72 HTMLPayload::HTMLNo => {
73 write!(f, "false")
74 }
75 }
76 }
77}