Skip to content

Commit

Permalink
Implement IntoDeserializer for public deserializers
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingun committed Oct 20, 2024
1 parent 9218684 commit 83d2957
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

- [#826]: Implement `From<String>` and `From<Cow<str>>` for `quick_xml::de::Text`.
- [#826]: Make `SimpleTypeDeserializer` and `SimpleTypeSerializer` public.
- [#826]: Implement `IntoDeserializer` for `&mut Deserializer`.

### Bug Fixes

Expand Down
17 changes: 16 additions & 1 deletion src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2019,7 +2019,9 @@ use crate::{
reader::Reader,
utils::CowRef,
};
use serde::de::{self, Deserialize, DeserializeOwned, DeserializeSeed, SeqAccess, Visitor};
use serde::de::{
self, Deserialize, DeserializeOwned, DeserializeSeed, IntoDeserializer, SeqAccess, Visitor,
};
use std::borrow::Cow;
#[cfg(feature = "overlapped-lists")]
use std::collections::VecDeque;
Expand Down Expand Up @@ -2990,6 +2992,19 @@ where
}
}

impl<'de, 'a, R, E> IntoDeserializer<'de, DeError> for &'a mut Deserializer<'de, R, E>
where
R: XmlRead<'de>,
E: EntityResolver,
{
type Deserializer = Self;

#[inline]
fn into_deserializer(self) -> Self {
self
}
}

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

/// Helper struct that contains a state for an algorithm of converting events
Expand Down
13 changes: 12 additions & 1 deletion src/de/simple_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ use crate::escape::unescape;
use crate::utils::CowRef;
use memchr::memchr;
use serde::de::value::UnitDeserializer;
use serde::de::{DeserializeSeed, Deserializer, EnumAccess, SeqAccess, VariantAccess, Visitor};
use serde::de::{
DeserializeSeed, Deserializer, EnumAccess, IntoDeserializer, SeqAccess, VariantAccess, Visitor,
};
use serde::serde_if_integer128;
use std::borrow::Cow;
use std::ops::Range;
Expand Down Expand Up @@ -770,6 +772,15 @@ impl<'de, 'a> EnumAccess<'de> for SimpleTypeDeserializer<'de, 'a> {
}
}

impl<'de, 'a> IntoDeserializer<'de, DeError> for SimpleTypeDeserializer<'de, 'a> {
type Deserializer = Self;

#[inline]
fn into_deserializer(self) -> Self {
self
}
}

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

#[cfg(test)]
Expand Down

0 comments on commit 83d2957

Please sign in to comment.