Merge pull request #2290 from Mingun/enum-tests-and-cleanup
Remove unused `impl` and unnecessary struct-wrapper around tuple
This commit is contained in:
commit
92bfc8d3af
@ -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,27 +815,11 @@ mod content {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'de, T> DeserializeSeed<'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 deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
|
||||||
where
|
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
// Internally tagged enums are only supported in self-describing
|
|
||||||
// formats.
|
|
||||||
deserializer.deserialize_any(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'de, T> Visitor<'de> for TaggedContentVisitor<'de, T>
|
|
||||||
where
|
|
||||||
T: Deserialize<'de>,
|
|
||||||
{
|
|
||||||
type Value = TaggedContent<'de, T>;
|
|
||||||
|
|
||||||
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)
|
||||||
@ -858,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>
|
||||||
@ -886,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),
|
|
||||||
}),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1356,9 +1356,7 @@ fn deserialize_internally_tagged_enum(
|
|||||||
params,
|
params,
|
||||||
variant,
|
variant,
|
||||||
cattrs,
|
cattrs,
|
||||||
quote! {
|
quote!(__deserializer),
|
||||||
_serde::__private::de::ContentDeserializer::<__D::Error>::new(__tagged.content)
|
|
||||||
},
|
|
||||||
));
|
));
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
@ -1374,11 +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(__content);
|
||||||
|
|
||||||
match __tagged.tag {
|
match __tag {
|
||||||
#(#variant_arms)*
|
#(#variant_arms)*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user