Merge pull request #254 from erickt/error-custom
feat(errors): Switch Error::custom to use Into<String>
This commit is contained in:
commit
708a310ab0
@ -12,7 +12,7 @@ mod from_primitive;
|
||||
/// `Deserializer` error.
|
||||
pub trait Error: Sized + error::Error {
|
||||
/// Raised when there is general error when deserializing a type.
|
||||
fn custom(msg: String) -> Self;
|
||||
fn custom<T: Into<String>>(msg: T) -> Self;
|
||||
|
||||
/// Raised when a `Deserialize` type unexpectedly hit the end of the stream.
|
||||
fn end_of_stream() -> Self;
|
||||
|
@ -50,7 +50,7 @@ pub enum Error {
|
||||
}
|
||||
|
||||
impl de::Error for Error {
|
||||
fn custom(msg: String) -> Self { Error::Custom(msg) }
|
||||
fn custom<T: Into<String>>(msg: T) -> Self { Error::Custom(msg.into()) }
|
||||
fn end_of_stream() -> Self { Error::EndOfStream }
|
||||
fn invalid_type(ty: de::Type) -> Self { Error::InvalidType(ty) }
|
||||
fn invalid_value(msg: &str) -> Self { Error::InvalidValue(msg.to_owned()) }
|
||||
|
@ -10,7 +10,7 @@ pub mod impls;
|
||||
/// `Serializer` error.
|
||||
pub trait Error: Sized + error::Error {
|
||||
/// Raised when there is general error when deserializing a type.
|
||||
fn custom(msg: String) -> Self;
|
||||
fn custom<T: Into<String>>(msg: T) -> Self;
|
||||
|
||||
/// Raised when a `Serialize` was passed an incorrect value.
|
||||
fn invalid_value(msg: &str) -> Self {
|
||||
|
@ -22,7 +22,7 @@ pub enum Error {
|
||||
}
|
||||
|
||||
impl serde::de::Error for Error {
|
||||
fn custom(_: String) -> Error { Error::Syntax }
|
||||
fn custom<T: Into<String>>(_: T) -> Error { Error::Syntax }
|
||||
|
||||
fn end_of_stream() -> Error { Error::EndOfStream }
|
||||
|
||||
|
@ -19,7 +19,7 @@ pub enum Error {
|
||||
}
|
||||
|
||||
impl serde::de::Error for Error {
|
||||
fn custom(_: String) -> Error { Error::Syntax }
|
||||
fn custom<T: Into<String>>(_: T) -> Error { Error::Syntax }
|
||||
|
||||
fn end_of_stream() -> Error { Error::EndOfStream }
|
||||
|
||||
|
@ -35,7 +35,7 @@ pub enum Error {
|
||||
}
|
||||
|
||||
impl serde::de::Error for Error {
|
||||
fn custom(_: String) -> Error { Error::Syntax }
|
||||
fn custom<T: Into<String>>(_: T) -> Error { Error::Syntax }
|
||||
|
||||
fn end_of_stream() -> Error { Error::EndOfStream }
|
||||
|
||||
|
@ -17,7 +17,7 @@ pub enum Error {
|
||||
}
|
||||
|
||||
impl serde::de::Error for Error {
|
||||
fn custom(_: String) -> Error { Error::Syntax }
|
||||
fn custom<T: Into<String>>(_: T) -> Error { Error::Syntax }
|
||||
|
||||
fn end_of_stream() -> Error { Error::EndOfStream }
|
||||
|
||||
|
@ -10,11 +10,11 @@ use serde::bytes::{ByteBuf, Bytes};
|
||||
struct Error;
|
||||
|
||||
impl serde::ser::Error for Error {
|
||||
fn custom(_: String) -> Error { Error }
|
||||
fn custom<T: Into<String>>(_: T) -> Error { Error }
|
||||
}
|
||||
|
||||
impl serde::de::Error for Error {
|
||||
fn custom(_: String) -> Error { Error }
|
||||
fn custom<T: Into<String>>(_: T) -> Error { Error }
|
||||
|
||||
fn end_of_stream() -> Error { Error }
|
||||
}
|
||||
|
@ -416,7 +416,7 @@ pub enum Error {
|
||||
}
|
||||
|
||||
impl ser::Error for Error {
|
||||
fn custom(_: String) -> Error { Error::SyntaxError }
|
||||
fn custom<T: Into<String>>(_: T) -> Error { Error::SyntaxError }
|
||||
|
||||
fn invalid_value(msg: &str) -> Error {
|
||||
Error::InvalidValue(msg.to_owned())
|
||||
@ -424,7 +424,7 @@ impl ser::Error for Error {
|
||||
}
|
||||
|
||||
impl de::Error for Error {
|
||||
fn custom(_: String) -> Error { Error::SyntaxError }
|
||||
fn custom<T: Into<String>>(_: T) -> Error { Error::SyntaxError }
|
||||
|
||||
fn end_of_stream() -> Error { Error::EndOfStreamError }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user