Rename VariantAccess methods to not conflict with Deserializer

This commit is contained in:
David Tolnay 2017-04-15 12:35:04 -07:00
parent 4354aab93a
commit c13a37d4db
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
6 changed files with 49 additions and 51 deletions

View File

@ -1025,7 +1025,7 @@ impl<'de> Visitor<'de> for OsStringVisitor {
use std::os::unix::ffi::OsStringExt;
match try!(data.variant()) {
(OsStringKind::Unix, variant) => variant.deserialize_newtype().map(OsString::from_vec),
(OsStringKind::Unix, v) => v.newtype_variant().map(OsString::from_vec),
(OsStringKind::Windows, _) => Err(Error::custom("cannot deserialize Windows OS string on Unix",),),
}
}
@ -1038,10 +1038,8 @@ impl<'de> Visitor<'de> for OsStringVisitor {
use std::os::windows::ffi::OsStringExt;
match try!(data.variant()) {
(OsStringKind::Windows, variant) => {
variant
.deserialize_newtype::<Vec<u16>>()
.map(|vec| OsString::from_wide(&vec))
(OsStringKind::Windows, v) => {
v.newtype_variant::<Vec<u16>>().map(|vec| OsString::from_wide(&vec))
}
(OsStringKind::Unix, _) => Err(Error::custom("cannot deserialize Unix OS string on Windows",),),
}
@ -1539,8 +1537,8 @@ where
A: EnumAccess<'de>,
{
match try!(data.variant()) {
(Field::Ok, variant) => variant.deserialize_newtype().map(Ok),
(Field::Err, variant) => variant.deserialize_newtype().map(Err),
(Field::Ok, v) => v.newtype_variant().map(Ok),
(Field::Err, v) => v.newtype_variant().map(Err),
}
}
}

View File

@ -1697,31 +1697,31 @@ pub trait VariantAccess<'de>: Sized {
/// # impl<'de> VariantAccess<'de> for X {
/// # type Error = value::Error;
/// #
/// fn deserialize_unit(self) -> Result<(), Self::Error> {
/// fn unit_variant(self) -> Result<(), Self::Error> {
/// // What the data actually contained; suppose it is a tuple variant.
/// let unexp = Unexpected::TupleVariant;
/// Err(de::Error::invalid_type(unexp, &"unit variant"))
/// }
/// #
/// # fn deserialize_newtype_seed<T>(self, _: T) -> Result<T::Value, Self::Error>
/// # fn newtype_variant_seed<T>(self, _: T) -> Result<T::Value, Self::Error>
/// # where T: DeserializeSeed<'de>
/// # { unimplemented!() }
/// #
/// # fn deserialize_tuple<V>(self, _: usize, _: V) -> Result<V::Value, Self::Error>
/// # fn tuple_variant<V>(self, _: usize, _: V) -> Result<V::Value, Self::Error>
/// # where V: Visitor<'de>
/// # { unimplemented!() }
/// #
/// # fn deserialize_struct<V>(self, _: &[&str], _: V) -> Result<V::Value, Self::Error>
/// # fn struct_variant<V>(self, _: &[&str], _: V) -> Result<V::Value, Self::Error>
/// # where V: Visitor<'de>
/// # { unimplemented!() }
/// # }
/// ```
fn deserialize_unit(self) -> Result<(), Self::Error>;
fn unit_variant(self) -> Result<(), Self::Error>;
/// Called when deserializing a variant with a single value.
///
/// `Deserialize` implementations should typically use
/// `VariantAccess::deserialize_newtype` instead.
/// `VariantAccess::newtype_variant` instead.
///
/// If the data contains a different type of variant, the following
/// `invalid_type` error should be constructed:
@ -1734,11 +1734,11 @@ pub trait VariantAccess<'de>: Sized {
/// # impl<'de> VariantAccess<'de> for X {
/// # type Error = value::Error;
/// #
/// # fn deserialize_unit(self) -> Result<(), Self::Error> {
/// # fn unit_variant(self) -> Result<(), Self::Error> {
/// # unimplemented!()
/// # }
/// #
/// fn deserialize_newtype_seed<T>(self, _seed: T) -> Result<T::Value, Self::Error>
/// fn newtype_variant_seed<T>(self, _seed: T) -> Result<T::Value, Self::Error>
/// where T: DeserializeSeed<'de>
/// {
/// // What the data actually contained; suppose it is a unit variant.
@ -1746,16 +1746,16 @@ pub trait VariantAccess<'de>: Sized {
/// Err(de::Error::invalid_type(unexp, &"newtype variant"))
/// }
/// #
/// # fn deserialize_tuple<V>(self, _: usize, _: V) -> Result<V::Value, Self::Error>
/// # fn tuple_variant<V>(self, _: usize, _: V) -> Result<V::Value, Self::Error>
/// # where V: Visitor<'de>
/// # { unimplemented!() }
/// #
/// # fn deserialize_struct<V>(self, _: &[&str], _: V) -> Result<V::Value, Self::Error>
/// # fn struct_variant<V>(self, _: &[&str], _: V) -> Result<V::Value, Self::Error>
/// # where V: Visitor<'de>
/// # { unimplemented!() }
/// # }
/// ```
fn deserialize_newtype_seed<T>(self, seed: T) -> Result<T::Value, Self::Error>
fn newtype_variant_seed<T>(self, seed: T) -> Result<T::Value, Self::Error>
where
T: DeserializeSeed<'de>;
@ -1765,11 +1765,11 @@ pub trait VariantAccess<'de>: Sized {
/// `VariantAccess` implementations should not override the default
/// behavior.
#[inline]
fn deserialize_newtype<T>(self) -> Result<T, Self::Error>
fn newtype_variant<T>(self) -> Result<T, Self::Error>
where
T: Deserialize<'de>,
{
self.deserialize_newtype_seed(PhantomData)
self.newtype_variant_seed(PhantomData)
}
/// Called when deserializing a tuple-like variant.
@ -1787,15 +1787,15 @@ pub trait VariantAccess<'de>: Sized {
/// # impl<'de> VariantAccess<'de> for X {
/// # type Error = value::Error;
/// #
/// # fn deserialize_unit(self) -> Result<(), Self::Error> {
/// # fn unit_variant(self) -> Result<(), Self::Error> {
/// # unimplemented!()
/// # }
/// #
/// # fn deserialize_newtype_seed<T>(self, _: T) -> Result<T::Value, Self::Error>
/// # fn newtype_variant_seed<T>(self, _: T) -> Result<T::Value, Self::Error>
/// # where T: DeserializeSeed<'de>
/// # { unimplemented!() }
/// #
/// fn deserialize_tuple<V>(self,
/// fn tuple_variant<V>(self,
/// _len: usize,
/// _visitor: V) -> Result<V::Value, Self::Error>
/// where V: Visitor<'de>
@ -1805,12 +1805,12 @@ pub trait VariantAccess<'de>: Sized {
/// Err(de::Error::invalid_type(unexp, &"tuple variant"))
/// }
/// #
/// # fn deserialize_struct<V>(self, _: &[&str], _: V) -> Result<V::Value, Self::Error>
/// # fn struct_variant<V>(self, _: &[&str], _: V) -> Result<V::Value, Self::Error>
/// # where V: Visitor<'de>
/// # { unimplemented!() }
/// # }
/// ```
fn deserialize_tuple<V>(self, len: usize, visitor: V) -> Result<V::Value, Self::Error>
fn tuple_variant<V>(self, len: usize, visitor: V) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>;
@ -1829,19 +1829,19 @@ pub trait VariantAccess<'de>: Sized {
/// # impl<'de> VariantAccess<'de> for X {
/// # type Error = value::Error;
/// #
/// # fn deserialize_unit(self) -> Result<(), Self::Error> {
/// # fn unit_variant(self) -> Result<(), Self::Error> {
/// # unimplemented!()
/// # }
/// #
/// # fn deserialize_newtype_seed<T>(self, _: T) -> Result<T::Value, Self::Error>
/// # fn newtype_variant_seed<T>(self, _: T) -> Result<T::Value, Self::Error>
/// # where T: DeserializeSeed<'de>
/// # { unimplemented!() }
/// #
/// # fn deserialize_tuple<V>(self, _: usize, _: V) -> Result<V::Value, Self::Error>
/// # fn tuple_variant<V>(self, _: usize, _: V) -> Result<V::Value, Self::Error>
/// # where V: Visitor<'de>
/// # { unimplemented!() }
/// #
/// fn deserialize_struct<V>(self,
/// fn struct_variant<V>(self,
/// _fields: &'static [&'static str],
/// _visitor: V) -> Result<V::Value, Self::Error>
/// where V: Visitor<'de>
@ -1852,7 +1852,7 @@ pub trait VariantAccess<'de>: Sized {
/// }
/// # }
/// ```
fn deserialize_struct<V>(
fn struct_variant<V>(
self,
fields: &'static [&'static str],
visitor: V,

View File

@ -1120,25 +1120,25 @@ mod private {
{
type Error = E;
fn deserialize_unit(self) -> Result<(), Self::Error> {
fn unit_variant(self) -> Result<(), Self::Error> {
Ok(())
}
fn deserialize_newtype_seed<T>(self, _seed: T) -> Result<T::Value, Self::Error>
fn newtype_variant_seed<T>(self, _seed: T) -> Result<T::Value, Self::Error>
where
T: de::DeserializeSeed<'de>,
{
Err(de::Error::invalid_type(Unexpected::UnitVariant, &"newtype variant"),)
}
fn deserialize_tuple<V>(self, _len: usize, _visitor: V) -> Result<V::Value, Self::Error>
fn tuple_variant<V>(self, _len: usize, _visitor: V) -> Result<V::Value, Self::Error>
where
V: de::Visitor<'de>,
{
Err(de::Error::invalid_type(Unexpected::UnitVariant, &"tuple variant"),)
}
fn deserialize_struct<V>(
fn struct_variant<V>(
self,
_fields: &'static [&'static str],
_visitor: V,

View File

@ -1056,14 +1056,14 @@ mod content {
{
type Error = E;
fn deserialize_unit(self) -> Result<(), E> {
fn unit_variant(self) -> Result<(), E> {
match self.value {
Some(value) => de::Deserialize::deserialize(ContentDeserializer::new(value)),
None => Ok(()),
}
}
fn deserialize_newtype_seed<T>(self, seed: T) -> Result<T::Value, E>
fn newtype_variant_seed<T>(self, seed: T) -> Result<T::Value, E>
where
T: de::DeserializeSeed<'de>,
{
@ -1075,7 +1075,7 @@ mod content {
}
}
fn deserialize_tuple<V>(self, _len: usize, visitor: V) -> Result<V::Value, Self::Error>
fn tuple_variant<V>(self, _len: usize, visitor: V) -> Result<V::Value, Self::Error>
where
V: de::Visitor<'de>,
{
@ -1088,7 +1088,7 @@ mod content {
}
}
fn deserialize_struct<V>(
fn struct_variant<V>(
self,
_fields: &'static [&'static str],
visitor: V,
@ -1448,14 +1448,14 @@ mod content {
{
type Error = E;
fn deserialize_unit(self) -> Result<(), E> {
fn unit_variant(self) -> Result<(), E> {
match self.value {
Some(value) => de::Deserialize::deserialize(ContentRefDeserializer::new(value)),
None => Ok(()),
}
}
fn deserialize_newtype_seed<T>(self, seed: T) -> Result<T::Value, E>
fn newtype_variant_seed<T>(self, seed: T) -> Result<T::Value, E>
where
T: de::DeserializeSeed<'de>,
{
@ -1467,7 +1467,7 @@ mod content {
}
}
fn deserialize_tuple<V>(self, _len: usize, visitor: V) -> Result<V::Value, Self::Error>
fn tuple_variant<V>(self, _len: usize, visitor: V) -> Result<V::Value, Self::Error>
where
V: de::Visitor<'de>,
{
@ -1480,7 +1480,7 @@ mod content {
}
}
fn deserialize_struct<V>(
fn struct_variant<V>(
self,
_fields: &'static [&'static str],
visitor: V,

View File

@ -299,7 +299,7 @@ fn deserialize_tuple(
let dispatch = if let Some(deserializer) = deserializer {
quote!(_serde::Deserializer::deserialize_tuple(#deserializer, #nfields, #visitor_expr))
} else if is_enum {
quote!(_serde::de::VariantAccess::deserialize_tuple(__variant, #nfields, #visitor_expr))
quote!(_serde::de::VariantAccess::tuple_variant(__variant, #nfields, #visitor_expr))
} else if nfields == 1 {
let type_name = cattrs.name().deserialize_name();
quote!(_serde::Deserializer::deserialize_newtype_struct(__deserializer, #type_name, #visitor_expr))
@ -508,7 +508,7 @@ fn deserialize_struct(
}
} else if is_enum {
quote! {
_serde::de::VariantAccess::deserialize_struct(__variant, FIELDS, #visitor_expr)
_serde::de::VariantAccess::struct_variant(__variant, FIELDS, #visitor_expr)
}
} else {
let type_name = cattrs.name().deserialize_name();
@ -1048,7 +1048,7 @@ fn deserialize_externally_tagged_variant(
Style::Unit => {
let this = &params.this;
quote_block! {
try!(_serde::de::VariantAccess::deserialize_unit(__variant));
try!(_serde::de::VariantAccess::unit_variant(__variant));
_serde::export::Ok(#this::#variant_ident)
}
}
@ -1163,7 +1163,7 @@ fn deserialize_externally_tagged_newtype_variant(
let field_ty = &field.ty;
quote_expr! {
_serde::export::Result::map(
_serde::de::VariantAccess::deserialize_newtype::<#field_ty>(__variant),
_serde::de::VariantAccess::newtype_variant::<#field_ty>(__variant),
#this::#variant_ident)
}
}
@ -1172,7 +1172,7 @@ fn deserialize_externally_tagged_newtype_variant(
quote_block! {
#wrapper
_serde::export::Result::map(
_serde::de::VariantAccess::deserialize_newtype::<#wrapper_ty>(__variant),
_serde::de::VariantAccess::newtype_variant::<#wrapper_ty>(__variant),
|__wrapper| #this::#variant_ident(__wrapper.value))
}
}

View File

@ -478,7 +478,7 @@ impl<'de, 'a> EnumAccess<'de> for DeserializerEnumVisitor<'a, 'de> {
impl<'de, 'a> VariantAccess<'de> for DeserializerEnumVisitor<'a, 'de> {
type Error = Error;
fn deserialize_unit(self) -> Result<(), Error> {
fn unit_variant(self) -> Result<(), Error> {
match self.de.tokens.first() {
Some(&Token::UnitVariant(_, _)) => {
self.de.next_token();
@ -489,7 +489,7 @@ impl<'de, 'a> VariantAccess<'de> for DeserializerEnumVisitor<'a, 'de> {
}
}
fn deserialize_newtype_seed<T>(self, seed: T) -> Result<T::Value, Self::Error>
fn newtype_variant_seed<T>(self, seed: T) -> Result<T::Value, Self::Error>
where
T: DeserializeSeed<'de>,
{
@ -503,7 +503,7 @@ impl<'de, 'a> VariantAccess<'de> for DeserializerEnumVisitor<'a, 'de> {
}
}
fn deserialize_tuple<V>(self, len: usize, visitor: V) -> Result<V::Value, Error>
fn tuple_variant<V>(self, len: usize, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
@ -532,7 +532,7 @@ impl<'de, 'a> VariantAccess<'de> for DeserializerEnumVisitor<'a, 'de> {
}
}
fn deserialize_struct<V>(self, fields: &'static [&'static str], visitor: V) -> Result<V::Value, Error>
fn struct_variant<V>(self, fields: &'static [&'static str], visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{