Skip to content

Commit 3783a30

Browse files
committed
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
1 parent b61ec84 commit 3783a30

File tree

2 files changed

+10
-22
lines changed

2 files changed

+10
-22
lines changed

serde/src/private/de.rs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -797,19 +797,13 @@ mod content {
797797
/// Used by generated code to deserialize an internally tagged enum.
798798
///
799799
/// Not public API.
800-
pub struct TaggedContent<'de, T> {
801-
pub tag: T,
802-
pub content: Content<'de>,
803-
}
804-
805-
/// Not public API.
806-
pub struct TaggedContentVisitor<'de, T> {
800+
pub struct TaggedContentVisitor<T> {
807801
tag_name: &'static str,
808802
expecting: &'static str,
809-
value: PhantomData<TaggedContent<'de, T>>,
803+
value: PhantomData<T>,
810804
}
811805

812-
impl<'de, T> TaggedContentVisitor<'de, T> {
806+
impl<T> TaggedContentVisitor<T> {
813807
/// Visitor for the content of an internally tagged enum with the given
814808
/// tag name.
815809
pub fn new(name: &'static str, expecting: &'static str) -> Self {
@@ -821,11 +815,11 @@ mod content {
821815
}
822816
}
823817

824-
impl<'de, T> Visitor<'de> for TaggedContentVisitor<'de, T>
818+
impl<'de, T> Visitor<'de> for TaggedContentVisitor<T>
825819
where
826820
T: Deserialize<'de>,
827821
{
828-
type Value = TaggedContent<'de, T>;
822+
type Value = (T, Content<'de>);
829823

830824
fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
831825
fmt.write_str(self.expecting)
@@ -842,10 +836,7 @@ mod content {
842836
}
843837
};
844838
let rest = de::value::SeqAccessDeserializer::new(seq);
845-
Ok(TaggedContent {
846-
tag,
847-
content: try!(Content::deserialize(rest)),
848-
})
839+
Ok((tag, try!(Content::deserialize(rest))))
849840
}
850841

851842
fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
@@ -870,10 +861,7 @@ mod content {
870861
}
871862
match tag {
872863
None => Err(de::Error::missing_field(self.tag_name)),
873-
Some(tag) => Ok(TaggedContent {
874-
tag,
875-
content: Content::Map(vec),
876-
}),
864+
Some(tag) => Ok((tag, Content::Map(vec))),
877865
}
878866
}
879867
}

serde_derive/src/de.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,12 +1372,12 @@ fn deserialize_internally_tagged_enum(
13721372

13731373
#variants_stmt
13741374

1375-
let __tagged = try!(_serde::Deserializer::deserialize_any(
1375+
let (__tag, __content) = try!(_serde::Deserializer::deserialize_any(
13761376
__deserializer,
13771377
_serde::__private::de::TaggedContentVisitor::<__Field>::new(#tag, #expecting)));
1378-
let __deserializer = _serde::__private::de::ContentDeserializer::<__D::Error>::new(__tagged.content);
1378+
let __deserializer = _serde::__private::de::ContentDeserializer::<__D::Error>::new(__content);
13791379

1380-
match __tagged.tag {
1380+
match __tag {
13811381
#(#variant_arms)*
13821382
}
13831383
}

0 commit comments

Comments
 (0)