add ErrorKind::DeserializeAnyNotSupported (#211)

This commit is contained in:
Ty Overby 2017-10-11 10:38:35 -07:00 committed by GitHub
parent d04ba007dc
commit 45e70e297e
3 changed files with 10 additions and 2 deletions

View File

@ -2,6 +2,8 @@
name = "bincode"
version = "0.8.1"
authors = ["Ty Overby <ty@pre-alpha.com>", "Francesco Mazzoli <f@mazzo.li>", "David Tolnay <dtolnay@gmail.com>", "Daniel Griffen"]
# Adding ErrorKind::DeserializeAnyNotSupported is a breaking change
publish = false
repository = "https://github.com/TyOverby/bincode"

View File

@ -85,8 +85,7 @@ where R: BincodeRead<'de>, S: SizeLimit, E: ByteOrder {
fn deserialize_any<V>(self, _visitor: V) -> Result<V::Value>
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<V>(self, visitor: V) -> Result<V::Value>

View File

@ -41,6 +41,9 @@ pub enum ErrorKind {
#[allow(missing_docs)]
detail: Option<String>
},
/// 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),
}