Merge pull request #254 from erickt/error-custom

feat(errors): Switch Error::custom to use Into<String>
This commit is contained in:
Erick Tryzelaar 2016-02-26 21:25:01 -08:00
commit 708a310ab0
9 changed files with 11 additions and 11 deletions

View File

@ -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;

View File

@ -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()) }

View File

@ -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 {

View File

@ -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 }

View File

@ -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 }

View File

@ -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 }

View File

@ -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 }

View File

@ -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 }
}

View File

@ -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 }