From ff6153be6cc85029bc497de7753726a1c9f26a83 Mon Sep 17 00:00:00 2001 From: Mingun Date: Sat, 19 Oct 2024 17:53:43 +0500 Subject: [PATCH] Implement IntoDeserializer for public deserializers --- Changelog.md | 1 + src/de/mod.rs | 17 ++++++++++++++++- src/de/simple_type.rs | 13 ++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index e20dbe8d..17729d7d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -17,6 +17,7 @@ - [#826]: Implement `From` and `From>` for `quick_xml::de::Text`. - [#826]: Make `SimpleTypeDeserializer` and `SimpleTypeSerializer` public. +- [#826]: Implement `IntoDeserializer` for `&mut Deserializer`. ### Bug Fixes diff --git a/src/de/mod.rs b/src/de/mod.rs index 681beecb..484c31b0 100644 --- a/src/de/mod.rs +++ b/src/de/mod.rs @@ -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; @@ -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 diff --git a/src/de/simple_type.rs b/src/de/simple_type.rs index c447eeab..fefa9e97 100644 --- a/src/de/simple_type.rs +++ b/src/de/simple_type.rs @@ -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; @@ -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)]