Created
March 28, 2019 21:01
-
-
Save gnuvince/3d544963ae1fd2cd933f4b45ef95774c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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