From 719eaff26b220cf968957494fffde9a05bf94758 Mon Sep 17 00:00:00 2001 From: masinc Date: Sat, 13 Aug 2022 15:01:16 +0900 Subject: [PATCH] Implement Display trait for serde_yaml::value::tagged::Tag --- src/value/tagged.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/value/tagged.rs b/src/value/tagged.rs index cf958b07..78f23e1b 100644 --- a/src/value/tagged.rs +++ b/src/value/tagged.rs @@ -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. @@ -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 @@ -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(&self, serializer: S) -> Result where