Skip to content

Instantly share code, notes, and snippets.

@gnuvince gnuvince/deals.rs
Created Mar 28, 2019

Embed
What would you like to do?
fn deserialize_deals<'de, D>(de: D) -> ::std::result::Result<HashMap<u8, BTreeSet<String>>, D::Error>
where D: Deserializer<'de>
{
struct DealsVisitor;
impl<'de> Visitor<'de> for DealsVisitor {
type Value = HashMap<u8, BTreeSet<String>>;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("an array representation of a map of deals")
}
fn visit_seq<A: SeqAccess<'de>>(self, mut seq: A) -> ::std::result::Result<Self::Value, A::Error> {
let mut out = HashMap::new();
while let Some((exchange, deal_ids)) = seq.next_element()? {
let deal_ids: BTreeSet<String> = deal_ids;
out.insert(exchange, deal_ids);
}
return Ok(out);
}
}
de.deserialize_map(DealsVisitor)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.