From f5fa06e761646ba083c1317a4ba0dcd58eefe99b Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Tue, 23 Jun 2020 17:47:00 +0000 Subject: [PATCH] Fix Deserializer::{from_slice, with_reader} types (#332) Having these in the impl block with a generic R paramter would make them unusable, at least without type annotations: error[E0282]: type annotations needed --> msg_socket2/src/socket.rs:45:32 | 45 | let mut deserializer = Deserializer::with_reader(bytes.as_slice(), DefaultOptions::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `R` error: aborting due to previous error For more information about this error, try `rustc --explain E0282`. Moving these into separate impl blocks, which set the type of the Deserializer to the return type of the functions, fixes this error. --- src/de/mod.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/de/mod.rs b/src/de/mod.rs index e1179ea98..eff2546d8 100644 --- a/src/de/mod.rs +++ b/src/de/mod.rs @@ -42,23 +42,27 @@ macro_rules! impl_deserialize_literal { }; } -impl<'de, R: BincodeRead<'de>, O: Options> Deserializer { +impl<'de, IR: Read, O: Options> Deserializer, O> { /// Creates a new Deserializer with a given `Read`er and options. - pub fn with_reader(r: IR, options: O) -> Deserializer, O> { + pub fn with_reader(r: IR, options: O) -> Self { Deserializer { reader: IoReader::new(r), options, } } +} +impl<'de, O: Options> Deserializer, O> { /// Creates a new Deserializer that will read from the given slice. - pub fn from_slice(slice: &'de [u8], options: O) -> Deserializer, O> { + pub fn from_slice(slice: &'de [u8], options: O) -> Self { Deserializer { reader: SliceReader::new(slice), options, } } +} +impl<'de, R: BincodeRead<'de>, O: Options> Deserializer { /// Creates a new Deserializer with the given `BincodeRead`er pub fn with_bincode_read(r: R, options: O) -> Deserializer { Deserializer { reader: r, options }