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

Commit

Permalink
Merge pull request #307 from masinc/impl_dispaly_for_tag
Browse files Browse the repository at this point in the history
Implement Display trait for serde_yaml::value::tagged::Tag
  • Loading branch information
dtolnay committed Aug 13, 2022
2 parents d282c40 + 719eaff commit 719f52e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/value/tagged.rs
Expand Up @@ -7,7 +7,7 @@ use serde::de::{
};
use serde::ser::{Serialize, SerializeMap, Serializer};
use std::cmp::Ordering;
use std::fmt::{self, Debug};
use std::fmt::{self, Debug, Display};
use std::hash::{Hash, Hasher};

/// A representation of YAML's `!Tag` syntax, used for enums.
Expand Down Expand Up @@ -67,10 +67,12 @@ impl Tag {
/// let tag = Tag::new("Thing");
/// assert!(tag == "Thing");
/// assert!(tag == "!Thing");
/// assert!(tag.to_string() == "!Thing");
///
/// let tag = Tag::new("!Thing");
/// assert!(tag == "Thing");
/// assert!(tag == "!Thing");
/// assert!(tag.to_string() == "!Thing");
/// ```
///
/// Such a tag would serialize to `!Thing` in YAML regardless of whether a
Expand Down Expand Up @@ -153,6 +155,12 @@ impl Debug for Tag {
}
}

impl Display for Tag {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "!{}", nobang(&self.string))
}
}

impl Serialize for TaggedValue {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand Down

0 comments on commit 719f52e

Please sign in to comment.