Skip to content

Commit

Permalink
Added format output to lookup (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjohnsonsmarty authored Oct 24, 2023
1 parent 00ff9a0 commit 5e6a4e1
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions smarty-rust-sdk/src/us_street_api/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ pub struct Lookup {
#[serde(rename = "match")]
pub match_strategy: MatchStrategy, // "match" in json

#[serde(rename = "format")]
pub format_output: OutputFormat,

#[serde(skip_serializing)]
pub results: Candidates
}
Expand All @@ -55,6 +58,7 @@ impl Default for Lookup {
max_candidates: 1,

match_strategy: Default::default(),
format_output: Default::default(),
results: vec![]
}
}
Expand Down Expand Up @@ -85,15 +89,14 @@ impl Lookup {
has_param("input_id".to_string(), self.input_id),
has_param("candidates".to_string(), max_candidates_string),
has_param("match".to_string(), self.match_strategy.to_string()),
has_param("format".to_string(), self.format_output.to_string()),
].iter()
.filter_map(Option::clone)
.collect::<Vec<_>>()
}
}

#[derive(Default, Debug, Clone, PartialEq, Serialize)]
#[serde(rename_all = "snake_case")]
#[allow(dead_code)]
pub enum MatchStrategy {
#[default]
Strict,
Expand All @@ -109,4 +112,22 @@ impl Display for MatchStrategy {
MatchStrategy::Enhanced => { write!(f, "enhanced") }
}
}
}

#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub enum OutputFormat {
#[default]
FormatDefault,
ProjectUsa,
Cass
}

impl Display for OutputFormat {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
OutputFormat::FormatDefault => { write!(f, "default") }
OutputFormat::ProjectUsa => { write!(f, "project-usa") }
OutputFormat::Cass => { write!(f, "cass") }
}
}
}

0 comments on commit 5e6a4e1

Please sign in to comment.