Skip to content

Commit

Permalink
Correctly forward deserialization of tuples to the deserializer's des…
Browse files Browse the repository at this point in the history
…erialize_seq
  • Loading branch information
Mingun authored and dralley committed Feb 6, 2023
1 parent b3ebf7a commit 221b57d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 90 deletions.
46 changes: 0 additions & 46 deletions src/de/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,6 @@ where
deserialize_primitives!(mut);

forward!(deserialize_unit);
forward!(deserialize_unit_struct(name: &'static str));
forward!(deserialize_newtype_struct(name: &'static str));

forward!(deserialize_map);
forward!(deserialize_struct(
Expand All @@ -505,27 +503,6 @@ where
deserialize_option!(self.map.de, self, visitor)
}

/// Tuple representation is the same as [sequences](#method.deserialize_seq).
fn deserialize_tuple<V>(self, _len: usize, visitor: V) -> Result<V::Value, DeError>
where
V: Visitor<'de>,
{
self.deserialize_seq(visitor)
}

/// Named tuple representation is the same as [unnamed tuples](#method.deserialize_tuple).
fn deserialize_tuple_struct<V>(
self,
_name: &'static str,
len: usize,
visitor: V,
) -> Result<V::Value, DeError>
where
V: Visitor<'de>,
{
self.deserialize_tuple(len, visitor)
}

/// Deserializes each `<tag>` in
/// ```xml
/// <any-tag>
Expand Down Expand Up @@ -765,8 +742,6 @@ where
deserialize_primitives!(mut);

forward!(deserialize_unit);
forward!(deserialize_unit_struct(name: &'static str));
forward!(deserialize_newtype_struct(name: &'static str));

forward!(deserialize_map);
forward!(deserialize_struct(
Expand All @@ -789,27 +764,6 @@ where
deserialize_option!(self.map.de, self, visitor)
}

/// Representation of tuples the same as [sequences](#method.deserialize_seq).
fn deserialize_tuple<V>(self, _len: usize, visitor: V) -> Result<V::Value, DeError>
where
V: Visitor<'de>,
{
self.deserialize_seq(visitor)
}

/// Representation of named tuples the same as [unnamed tuples](#method.deserialize_tuple).
fn deserialize_tuple_struct<V>(
self,
_name: &'static str,
len: usize,
visitor: V,
) -> Result<V::Value, DeError>
where
V: Visitor<'de>,
{
self.deserialize_tuple(len, visitor)
}

/// This method deserializes a sequence inside of element that itself is a
/// sequence element:
///
Expand Down
88 changes: 44 additions & 44 deletions src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1815,6 +1815,50 @@ macro_rules! deserialize_primitives {
self.deserialize_bytes(visitor)
}

/// Representation of the named units the same as [unnamed units](#method.deserialize_unit)
fn deserialize_unit_struct<V>(
self,
_name: &'static str,
visitor: V,
) -> Result<V::Value, DeError>
where
V: Visitor<'de>,
{
self.deserialize_unit(visitor)
}

fn deserialize_newtype_struct<V>(
self,
_name: &'static str,
visitor: V,
) -> Result<V::Value, DeError>
where
V: Visitor<'de>,
{
self.deserialize_tuple(1, visitor)
}

/// Representation of tuples the same as [sequences](#method.deserialize_seq).
fn deserialize_tuple<V>(self, _len: usize, visitor: V) -> Result<V::Value, DeError>
where
V: Visitor<'de>,
{
self.deserialize_seq(visitor)
}

/// Representation of named tuples the same as [unnamed tuples](#method.deserialize_tuple).
fn deserialize_tuple_struct<V>(
self,
_name: &'static str,
len: usize,
visitor: V,
) -> Result<V::Value, DeError>
where
V: Visitor<'de>,
{
self.deserialize_tuple(len, visitor)
}

/// Identifiers represented as [strings](#method.deserialize_str).
fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, DeError>
where
Expand Down Expand Up @@ -2424,50 +2468,6 @@ where
}
}

/// Representation of the names units the same as [unnamed units](#method.deserialize_unit)
fn deserialize_unit_struct<V>(
self,
_name: &'static str,
visitor: V,
) -> Result<V::Value, DeError>
where
V: Visitor<'de>,
{
self.deserialize_unit(visitor)
}

fn deserialize_newtype_struct<V>(
self,
_name: &'static str,
visitor: V,
) -> Result<V::Value, DeError>
where
V: Visitor<'de>,
{
self.deserialize_tuple(1, visitor)
}

/// Representation of tuples the same as [sequences](#method.deserialize_seq).
fn deserialize_tuple<V>(self, _len: usize, visitor: V) -> Result<V::Value, DeError>
where
V: Visitor<'de>,
{
self.deserialize_seq(visitor)
}

/// Representation of named tuples the same as [unnamed tuples](#method.deserialize_tuple).
fn deserialize_tuple_struct<V>(
self,
_name: &'static str,
len: usize,
visitor: V,
) -> Result<V::Value, DeError>
where
V: Visitor<'de>,
{
self.deserialize_tuple(len, visitor)
}

fn deserialize_enum<V>(
self,
_name: &'static str,
Expand Down

0 comments on commit 221b57d

Please sign in to comment.