Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Serialize using Tag's Display impl
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Aug 13, 2022
1 parent 1b671c4 commit c5ca887
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/value/tagged.rs
Expand Up @@ -166,8 +166,19 @@ impl Serialize for TaggedValue {
where
S: Serializer,
{
struct SerializeTag<'a>(&'a Tag);

impl<'a> Serialize for SerializeTag<'a> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.collect_str(self.0)
}
}

let mut map = serializer.serialize_map(Some(1))?;
map.serialize_entry(&format_args!("!{}", nobang(&self.tag.string)), &self.value)?;
map.serialize_entry(&SerializeTag(&self.tag), &self.value)?;
map.end()
}
}
Expand Down

0 comments on commit c5ca887

Please sign in to comment.