diff --git a/Cargo.toml b/Cargo.toml index d70737a8..851e8abf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,14 +27,13 @@ edition = "2021" [features] default = ["std", "derive"] std = ["alloc", "serde?/std"] -alloc = ["serde?/alloc", "serde-persistent-deserializer?/alloc"] +alloc = ["serde?/alloc"] derive = ["bincode_derive"] -serde = ["dep:serde", "serde-persistent-deserializer"] +serde = ["dep:serde"] [dependencies] bincode_derive = { path = "derive", version = "2.0.0-rc.3", optional = true } serde = { version = "1.0", default-features = false, optional = true } -serde-persistent-deserializer = { version = "0.2", default-features = false, optional = true } unty = "0.0.3" # Used for tests diff --git a/src/features/serde/de_borrowed.rs b/src/features/serde/de_borrowed.rs index 56378676..bbff29e9 100644 --- a/src/features/serde/de_borrowed.rs +++ b/src/features/serde/de_borrowed.rs @@ -6,7 +6,6 @@ use crate::{ }; use core::marker::PhantomData; use serde::de::*; -use serde_persistent_deserializer::AsTransientDeserializer; /// Serde decoder encapsulating a borrowed reader. pub struct BorrowedSerdeDecoder<'de, DE: BorrowDecoder<'de>> { @@ -14,6 +13,18 @@ pub struct BorrowedSerdeDecoder<'de, DE: BorrowDecoder<'de>> { pub(super) pd: PhantomData<&'de ()>, } +impl<'de, DE: BorrowDecoder<'de>> BorrowedSerdeDecoder<'de, DE> { + /// Return a type implementing `serde::Deserializer`. + pub fn as_deserializer<'a>( + &'a mut self, + ) -> impl serde::Deserializer<'de, Error = DecodeError> + 'a { + SerdeDecoder { + de: &mut self.de, + pd: PhantomData, + } + } +} + impl<'de, C: Config> BorrowedSerdeDecoder<'de, DecoderImpl, C>> { /// Creates the decoder from a borrowed slice. pub fn from_slice( @@ -32,23 +43,6 @@ impl<'de, C: Config> BorrowedSerdeDecoder<'de, DecoderImpl, C>> } } -impl<'de, DE: BorrowDecoder<'de>> AsTransientDeserializer<'de> for BorrowedSerdeDecoder<'de, DE> { - type Error = DecodeError; - - #[inline] - fn as_transient_deserializer<'a>(&'a mut self) -> impl Deserializer<'de, Error = Self::Error> { - SerdeDecoder { - de: &mut self.de, - pd: PhantomData, - } - } - - #[inline] - fn is_human_readable(&self) -> bool { - false - } -} - /// Attempt to decode a given type `D` from the given slice. Returns the decoded output and the amount of bytes read. /// /// See the [config](../config/index.html) module for more information on configurations. @@ -62,7 +56,7 @@ where { let mut serde_decoder = BorrowedSerdeDecoder::, C>>::from_slice(slice, config); - let result = D::deserialize(serde_decoder.as_transient_deserializer())?; + let result = D::deserialize(serde_decoder.as_deserializer())?; let bytes_read = slice.len() - serde_decoder.de.borrow_reader().slice.len(); Ok((result, bytes_read)) } @@ -76,7 +70,7 @@ where { let mut serde_decoder = BorrowedSerdeDecoder::, C>>::from_slice(slice, config); - T::deserialize(serde_decoder.as_transient_deserializer()) + T::deserialize(serde_decoder.as_deserializer()) } /// Decode a borrowed type from the given slice using a seed. Some parts of the decoded type are expected to be referring to the given slice @@ -91,7 +85,7 @@ where { let mut serde_decoder = BorrowedSerdeDecoder::, C>>::from_slice(slice, config); - seed.deserialize(serde_decoder.as_transient_deserializer()) + seed.deserialize(serde_decoder.as_deserializer()) } pub(super) struct SerdeDecoder<'a, 'de, DE: BorrowDecoder<'de>> { diff --git a/src/features/serde/de_owned.rs b/src/features/serde/de_owned.rs index c4a9dd1a..c39a20ec 100644 --- a/src/features/serde/de_owned.rs +++ b/src/features/serde/de_owned.rs @@ -6,7 +6,6 @@ use crate::{ IoReader, }; use serde::de::*; -use serde_persistent_deserializer::AsTransientDeserializer; use super::de_borrowed::borrow_decode_from_slice; @@ -15,6 +14,15 @@ pub struct OwnedSerdeDecoder { pub(super) de: DE, } +impl OwnedSerdeDecoder { + /// Return a type implementing `serde::Deserializer`. + pub fn as_deserializer<'a>( + &'a mut self, + ) -> impl for<'de> serde::Deserializer<'de, Error = DecodeError> + 'a { + SerdeDecoder { de: &mut self.de } + } +} + #[cfg(feature = "std")] impl<'r, C: Config, R: std::io::Read> OwnedSerdeDecoder, C>> { /// Creates the decoder from an `std::io::Read` implementor. @@ -42,20 +50,6 @@ impl OwnedSerdeDecoder> { } } -impl<'de, DE: Decoder> AsTransientDeserializer<'de> for OwnedSerdeDecoder { - type Error = DecodeError; - - #[inline] - fn as_transient_deserializer<'a>(&'a mut self) -> impl Deserializer<'de, Error = Self::Error> { - SerdeDecoder { de: &mut self.de } - } - - #[inline] - fn is_human_readable(&self) -> bool { - false - } -} - /// Attempt to decode a given type `D` from the given slice. Returns the decoded output and the amount of bytes read. /// /// Note that this does not work with borrowed types like `&str` or `&[u8]`. For that use [borrow_decode_from_slice]. @@ -85,7 +79,7 @@ pub fn decode_from_std_read<'r, D: DeserializeOwned, C: Config, R: std::io::Read ) -> Result { let mut serde_decoder = OwnedSerdeDecoder::, C>>::from_std_read(src, config); - D::deserialize(serde_decoder.as_transient_deserializer()) + D::deserialize(serde_decoder.as_deserializer()) } /// Attempt to decode a given type `D` from the given [Reader]. @@ -98,7 +92,7 @@ pub fn decode_from_reader( config: C, ) -> Result { let mut serde_decoder = OwnedSerdeDecoder::>::from_reader(reader, config); - D::deserialize(serde_decoder.as_transient_deserializer()) + D::deserialize(serde_decoder.as_deserializer()) } pub(super) struct SerdeDecoder<'a, DE: Decoder> {