From 45e70e297ed997d5bade1627e5f02c007a4116f0 Mon Sep 17 00:00:00 2001 From: Ty Overby Date: Wed, 11 Oct 2017 10:38:35 -0700 Subject: [PATCH] add ErrorKind::DeserializeAnyNotSupported (#211) --- Cargo.toml | 2 ++ src/de/mod.rs | 3 +-- src/internal.rs | 7 +++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 212f070..acc4636 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,8 @@ name = "bincode" version = "0.8.1" authors = ["Ty Overby ", "Francesco Mazzoli ", "David Tolnay ", "Daniel Griffen"] + +# Adding ErrorKind::DeserializeAnyNotSupported is a breaking change publish = false repository = "https://github.com/TyOverby/bincode" diff --git a/src/de/mod.rs b/src/de/mod.rs index 904a54c..396b897 100644 --- a/src/de/mod.rs +++ b/src/de/mod.rs @@ -85,8 +85,7 @@ where R: BincodeRead<'de>, S: SizeLimit, E: ByteOrder { fn deserialize_any(self, _visitor: V) -> Result where V: serde::de::Visitor<'de>, { - let message = "bincode does not support Deserializer::deserialize_any"; - Err(Error::custom(message)) + Err(Box::new(ErrorKind::DeserializeAnyNotSupported)) } fn deserialize_bool(self, visitor: V) -> Result diff --git a/src/internal.rs b/src/internal.rs index 89af172..8c100f2 100644 --- a/src/internal.rs +++ b/src/internal.rs @@ -41,6 +41,9 @@ pub enum ErrorKind { #[allow(missing_docs)] detail: Option }, + /// Serde has a deserialize_any method that lets the format hint to the + /// object which route to take in deserializing. + DeserializeAnyNotSupported, /// If (de)serializing a message takes more than the provided size limit, this /// error is returned. SizeLimit, @@ -56,6 +59,7 @@ impl error::Error for ErrorKind { ErrorKind::Io(ref err) => error::Error::description(err), ErrorKind::InvalidEncoding{desc, ..} => desc, ErrorKind::SequenceMustHaveLength => "bincode can't encode infinite sequences", + ErrorKind::DeserializeAnyNotSupported => "bincode doesn't support serde::Deserializer::deserialize_any", ErrorKind::SizeLimit => "the size limit for decoding has been reached", ErrorKind::Custom(ref msg) => msg, @@ -67,6 +71,7 @@ impl error::Error for ErrorKind { ErrorKind::Io(ref err) => Some(err), ErrorKind::InvalidEncoding{..} => None, ErrorKind::SequenceMustHaveLength => None, + ErrorKind::DeserializeAnyNotSupported => None, ErrorKind::SizeLimit => None, ErrorKind::Custom(_) => None, } @@ -92,6 +97,8 @@ impl fmt::Display for ErrorKind { write!(fmt, "bincode can only encode sequences and maps that have a knowable size ahead of time."), ErrorKind::SizeLimit => write!(fmt, "size limit was exceeded"), + ErrorKind::DeserializeAnyNotSupported=> + write!(fmt, "bincode does not support the serde::Deserializer::deserialize_any method"), ErrorKind::Custom(ref s) => s.fmt(fmt), }