diff --git a/serde2/src/json/error.rs b/serde2/src/json/error.rs index 3af53a3e..0c2cb32e 100644 --- a/serde2/src/json/error.rs +++ b/serde2/src/json/error.rs @@ -91,7 +91,7 @@ impl error::Error for Error { fn description(&self) -> &str { match *self { Error::SyntaxError(..) => "syntax error", - Error::IoError(ref error) => error.description(), + Error::IoError(_) => "input/output error", /* Error::ExpectedError(ref expected, _) => &expected, Error::MissingFieldError(_) => "missing field", @@ -100,12 +100,15 @@ impl error::Error for Error { } } - fn detail(&self) -> Option { +} + +impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { match *self { Error::SyntaxError(ref code, line, col) => { - Some(format!("{:?} at line {:?} column {:?}", code, line, col)) + write!(fmt, "{:?} at line {:?} column {:?}", code, line, col) } - Error::IoError(ref error) => error.detail(), + Error::IoError(ref error) => fmt::Display::fmt(error, fmt), /* Error::ExpectedError(ref expected, ref found) => { Some(format!("expected {}, found {}", expected, found)) diff --git a/src/json/error.rs b/src/json/error.rs index 91cf4c95..a6598004 100644 --- a/src/json/error.rs +++ b/src/json/error.rs @@ -92,27 +92,29 @@ impl error::Error for Error { fn description(&self) -> &str { match *self { Error::SyntaxError(..) => "syntax error", - Error::IoError(ref error) => error.description(), + Error::IoError(_) => "Input/Output error", Error::ExpectedError(ref expected, _) => &expected, Error::MissingFieldError(_) => "missing field", Error::UnknownVariantError(_) => "unknown variant", } } +} - fn detail(&self) -> Option { +impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { match *self { Error::SyntaxError(ref code, line, col) => { - Some(format!("{:?} at line {:?} column {:?}", code, line, col)) + write!(fmt, "{:?} at line {:?} column {:?}", code, line, col) } - Error::IoError(ref error) => error.detail(), + Error::IoError(ref error) => fmt::Display::fmt(error, fmt), Error::ExpectedError(ref expected, ref found) => { - Some(format!("expected {:?}, found {:?}", expected, found)) + write!(fmt, "expected {:?}, found {:?}", expected, found) } Error::MissingFieldError(ref field) => { - Some(format!("missing field {:?}", field)) + write!(fmt, "missing field {:?}", field) } Error::UnknownVariantError(ref variant) => { - Some(format!("unknown variant {:?}", variant)) + write!(fmt, "unknown variant {:?}", variant) } } }