Skip to content

Commit 839a176

Browse files
authored
Merge pull request #33 from TheEmeraldBee/master
Updated lookup to skip country serialization if it's none
2 parents a933881 + 6ce8f5a commit 839a176

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
*DS_Store*
1414
*.swp
1515
*.iml
16-
__MACOSX
16+
__MACOSX

smarty-rust-sdk/src/us_street_api/lookup.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub struct Lookup {
3838
#[serde(rename = "format")]
3939
pub format_output: OutputFormat,
4040

41-
pub county_source: CountySource,
41+
pub county_source: Option<CountySource>,
4242

4343
#[serde(skip_serializing)]
4444
pub results: Candidates,
@@ -79,7 +79,7 @@ impl Lookup {
7979
max_candidates_string = 5.to_string();
8080
}
8181

82-
vec![
82+
let mut res = vec![
8383
has_param("street".to_string(), self.street),
8484
has_param("street2".to_string(), self.street2),
8585
has_param("secondary".to_string(), self.secondary),
@@ -93,11 +93,13 @@ impl Lookup {
9393
has_param("candidates".to_string(), max_candidates_string),
9494
has_param("match".to_string(), self.match_strategy.to_string()),
9595
has_param("format".to_string(), self.format_output.to_string()),
96-
has_param("county_source".to_string(), self.county_source.to_string()),
97-
]
98-
.iter()
99-
.filter_map(Option::clone)
100-
.collect::<Vec<_>>()
96+
];
97+
98+
if let Some(source) = self.county_source {
99+
res.push(Some(("country_source".to_string(), source.to_string())));
100+
}
101+
102+
res.iter().filter_map(Option::clone).collect::<Vec<_>>()
101103
}
102104
}
103105

@@ -165,4 +167,4 @@ impl Display for CountySource {
165167
}
166168
}
167169
}
168-
}
170+
}

0 commit comments

Comments
 (0)