diff --git a/serde/src/ser/mod.rs b/serde/src/ser/mod.rs index 8fb2434fa..d89cd3a0b 100644 --- a/serde/src/ser/mod.rs +++ b/serde/src/ser/mod.rs @@ -1247,6 +1247,27 @@ pub trait Serializer: Sized { len: usize, ) -> Result; + /// Serialize a value with a semantic tag for the given format. + /// + /// Tagged values are a mechanism supported by some data formats + /// to add additional information to serialized values and to + /// introduce user-defined subtypes. + /// + /// The default behavior is to ignore the tag and to serialize + /// just the value. + fn serialize_tagged_value( + self, + _format: &'static str, + _tag: &U, + value: &T, + ) -> Result + where + T: Serialize, + U: Serialize, + { + value.serialize(self) + } + /// Collect an iterator as a sequence. /// /// The default implementation serializes each item yielded by the iterator