Skip to content

Commit

Permalink
Merge pull request #254 from erickt/error-custom
Browse files Browse the repository at this point in the history
feat(errors): Switch Error::custom to use Into<String>
  • Loading branch information
erickt committed Feb 27, 2016
2 parents 6ea632e + ec75f22 commit 708a310
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion serde/src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion serde/src/de/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) }
Expand Down
2 changes: 1 addition & 1 deletion serde/src/ser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion serde_tests/benches/bench_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
2 changes: 1 addition & 1 deletion serde_tests/benches/bench_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
2 changes: 1 addition & 1 deletion serde_tests/benches/bench_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
2 changes: 1 addition & 1 deletion serde_tests/benches/bench_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
4 changes: 2 additions & 2 deletions serde_tests/tests/test_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand Down
4 changes: 2 additions & 2 deletions serde_tests/tests/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,15 +416,15 @@ 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())
}
}

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 }

Expand Down

0 comments on commit 708a310

Please sign in to comment.