Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement IntoDeserializer for all Deserializers in serde::de::value module #2568

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 174 additions & 0 deletions serde/src/de/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,17 @@ where
}
}

impl<'de, E> IntoDeserializer<'de, E> for UnitDeserializer<E>
where
E: de::Error,
{
type Deserializer = Self;

fn into_deserializer(self) -> Self {
self
}
}

impl<E> Debug for UnitDeserializer<E> {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.debug_struct("UnitDeserializer").finish()
Expand Down Expand Up @@ -225,6 +236,18 @@ where
}
}

#[cfg(feature = "unstable")]
impl<'de, E> IntoDeserializer<'de, E> for NeverDeserializer<E>
where
E: de::Error,
{
type Deserializer = Self;

fn into_deserializer(self) -> Self {
self
}
}

////////////////////////////////////////////////////////////////////////////////

macro_rules! primitive_deserializer {
Expand Down Expand Up @@ -279,6 +302,17 @@ macro_rules! primitive_deserializer {
}
}

impl<'de, E> IntoDeserializer<'de, E> for $name<E>
where
E: de::Error,
{
type Deserializer = Self;

fn into_deserializer(self) -> Self {
self
}
}

impl<E> Debug for $name<E> {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter
Expand Down Expand Up @@ -369,6 +403,17 @@ where
}
}

impl<'de, E> IntoDeserializer<'de, E> for U32Deserializer<E>
where
E: de::Error,
{
type Deserializer = Self;

fn into_deserializer(self) -> Self {
self
}
}

impl<'de, E> de::EnumAccess<'de> for U32Deserializer<E>
where
E: de::Error,
Expand Down Expand Up @@ -458,6 +503,17 @@ where
}
}

impl<'de, 'a, E> IntoDeserializer<'de, E> for StrDeserializer<'a, E>
where
E: de::Error,
{
type Deserializer = Self;

fn into_deserializer(self) -> Self {
self
}
}

impl<'de, 'a, E> de::EnumAccess<'de> for StrDeserializer<'a, E>
where
E: de::Error,
Expand Down Expand Up @@ -537,6 +593,17 @@ where
}
}

impl<'de, E> IntoDeserializer<'de, E> for BorrowedStrDeserializer<'de, E>
where
E: de::Error,
{
type Deserializer = Self;

fn into_deserializer(self) -> Self {
self
}
}

impl<'de, E> de::EnumAccess<'de> for BorrowedStrDeserializer<'de, E>
where
E: de::Error,
Expand Down Expand Up @@ -640,6 +707,18 @@ where
}
}

#[cfg(any(feature = "std", feature = "alloc"))]
impl<'de, E> IntoDeserializer<'de, E> for StringDeserializer<E>
where
E: de::Error,
{
type Deserializer = Self;

fn into_deserializer(self) -> Self {
self
}
}

#[cfg(any(feature = "std", feature = "alloc"))]
impl<'de, E> de::EnumAccess<'de> for StringDeserializer<E>
where
Expand Down Expand Up @@ -748,6 +827,18 @@ where
}
}

#[cfg(any(feature = "std", feature = "alloc"))]
impl<'de, 'a, E> IntoDeserializer<'de, E> for CowStrDeserializer<'a, E>
where
E: de::Error,
{
type Deserializer = Self;

fn into_deserializer(self) -> Self {
self
}
}

#[cfg(any(feature = "std", feature = "alloc"))]
impl<'de, 'a, E> de::EnumAccess<'de> for CowStrDeserializer<'a, E>
where
Expand Down Expand Up @@ -825,6 +916,17 @@ where
}
}

impl<'de, 'a, E> IntoDeserializer<'de, E> for BytesDeserializer<'a, E>
where
E: de::Error,
{
type Deserializer = Self;

fn into_deserializer(self) -> Self {
self
}
}

impl<'a, E> Debug for BytesDeserializer<'a, E> {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter
Expand Down Expand Up @@ -873,6 +975,17 @@ where
}
}

impl<'de, E> IntoDeserializer<'de, E> for BorrowedBytesDeserializer<'de, E>
where
E: de::Error,
{
type Deserializer = Self;

fn into_deserializer(self) -> Self {
self
}
}

impl<'de, E> Debug for BorrowedBytesDeserializer<'de, E> {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter
Expand Down Expand Up @@ -952,6 +1065,19 @@ where
}
}

impl<'de, I, T, E> IntoDeserializer<'de, E> for SeqDeserializer<I, E>
where
I: Iterator<Item = T>,
T: IntoDeserializer<'de, E>,
E: de::Error,
{
type Deserializer = Self;

fn into_deserializer(self) -> Self {
self
}
}

impl<'de, I, T, E> de::SeqAccess<'de> for SeqDeserializer<I, E>
where
I: Iterator<Item = T>,
Expand Down Expand Up @@ -1083,6 +1209,17 @@ where
}
}

impl<'de, A> IntoDeserializer<'de, A::Error> for SeqAccessDeserializer<A>
where
A: de::SeqAccess<'de>,
{
type Deserializer = Self;

fn into_deserializer(self) -> Self {
self
}
}

////////////////////////////////////////////////////////////////////////////////

/// A deserializer that iterates over a map.
Expand Down Expand Up @@ -1197,6 +1334,21 @@ where
}
}

impl<'de, I, E> IntoDeserializer<'de, E> for MapDeserializer<'de, I, E>
where
I: Iterator,
I::Item: private::Pair,
First<I::Item>: IntoDeserializer<'de, E>,
Second<I::Item>: IntoDeserializer<'de, E>,
E: de::Error,
{
type Deserializer = Self;

fn into_deserializer(self) -> Self {
self
}
}

impl<'de, I, E> de::MapAccess<'de> for MapDeserializer<'de, I, E>
where
I: Iterator,
Expand Down Expand Up @@ -1498,6 +1650,17 @@ where
}
}

impl<'de, A> IntoDeserializer<'de, A::Error> for MapAccessDeserializer<A>
where
A: de::MapAccess<'de>,
{
type Deserializer = Self;

fn into_deserializer(self) -> Self {
self
}
}

impl<'de, A> de::EnumAccess<'de> for MapAccessDeserializer<A>
where
A: de::MapAccess<'de>,
Expand Down Expand Up @@ -1551,6 +1714,17 @@ where
}
}

impl<'de, A> IntoDeserializer<'de, A::Error> for EnumAccessDeserializer<A>
where
A: de::EnumAccess<'de>,
{
type Deserializer = Self;

fn into_deserializer(self) -> Self {
self
}
}

////////////////////////////////////////////////////////////////////////////////

mod private {
Expand Down