Remove TaggedContent, replace it by a tuple

That type does not give any benefits so we can avoid that hidden public but no-API struct
This commit is contained in:
Mingun
2022-10-02 19:34:33 +05:00
parent b61ec84886
commit 3783a30ae7
2 changed files with 10 additions and 22 deletions
+7 -19
View File
@@ -797,19 +797,13 @@ mod content {
/// Used by generated code to deserialize an internally tagged enum. /// Used by generated code to deserialize an internally tagged enum.
/// ///
/// Not public API. /// Not public API.
pub struct TaggedContent<'de, T> { pub struct TaggedContentVisitor<T> {
pub tag: T,
pub content: Content<'de>,
}
/// Not public API.
pub struct TaggedContentVisitor<'de, T> {
tag_name: &'static str, tag_name: &'static str,
expecting: &'static str, expecting: &'static str,
value: PhantomData<TaggedContent<'de, T>>, value: PhantomData<T>,
} }
impl<'de, T> TaggedContentVisitor<'de, T> { impl<T> TaggedContentVisitor<T> {
/// Visitor for the content of an internally tagged enum with the given /// Visitor for the content of an internally tagged enum with the given
/// tag name. /// tag name.
pub fn new(name: &'static str, expecting: &'static str) -> Self { pub fn new(name: &'static str, expecting: &'static str) -> Self {
@@ -821,11 +815,11 @@ mod content {
} }
} }
impl<'de, T> Visitor<'de> for TaggedContentVisitor<'de, T> impl<'de, T> Visitor<'de> for TaggedContentVisitor<T>
where where
T: Deserialize<'de>, T: Deserialize<'de>,
{ {
type Value = TaggedContent<'de, T>; type Value = (T, Content<'de>);
fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.write_str(self.expecting) fmt.write_str(self.expecting)
@@ -842,10 +836,7 @@ mod content {
} }
}; };
let rest = de::value::SeqAccessDeserializer::new(seq); let rest = de::value::SeqAccessDeserializer::new(seq);
Ok(TaggedContent { Ok((tag, try!(Content::deserialize(rest))))
tag,
content: try!(Content::deserialize(rest)),
})
} }
fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error> fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
@@ -870,10 +861,7 @@ mod content {
} }
match tag { match tag {
None => Err(de::Error::missing_field(self.tag_name)), None => Err(de::Error::missing_field(self.tag_name)),
Some(tag) => Ok(TaggedContent { Some(tag) => Ok((tag, Content::Map(vec))),
tag,
content: Content::Map(vec),
}),
} }
} }
} }
+3 -3
View File
@@ -1372,12 +1372,12 @@ fn deserialize_internally_tagged_enum(
#variants_stmt #variants_stmt
let __tagged = try!(_serde::Deserializer::deserialize_any( let (__tag, __content) = try!(_serde::Deserializer::deserialize_any(
__deserializer, __deserializer,
_serde::__private::de::TaggedContentVisitor::<__Field>::new(#tag, #expecting))); _serde::__private::de::TaggedContentVisitor::<__Field>::new(#tag, #expecting)));
let __deserializer = _serde::__private::de::ContentDeserializer::<__D::Error>::new(__tagged.content); let __deserializer = _serde::__private::de::ContentDeserializer::<__D::Error>::new(__content);
match __tagged.tag { match __tag {
#(#variant_arms)* #(#variant_arms)*
} }
} }