From cd6c9d972bdd1245434146c190022ba9c1a193d1 Mon Sep 17 00:00:00 2001 From: Zhiming Wang Date: Sun, 31 May 2020 13:51:56 +0800 Subject: [PATCH] Fix std::error::Error::description deprecation --- src/util/error.rs | 12 +++++------- src/util/format/pixel.rs | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/util/error.rs b/src/util/error.rs index eb86a70..db52657 100644 --- a/src/util/error.rs +++ b/src/util/error.rs @@ -111,6 +111,8 @@ impl Into for Error { } } +impl error::Error for Error {} + impl From for io::Error { fn from(value: Error) -> io::Error { io::Error::new(io::ErrorKind::Other, value) @@ -119,7 +121,9 @@ impl From for io::Error { impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - f.write_str(error::Error::description(self)) + f.write_str(unsafe { + from_utf8_unchecked(CStr::from_ptr(STRINGS[index(self)].as_ptr()).to_bytes()) + }) } } @@ -311,9 +315,3 @@ pub fn register_all() { ); } } - -impl error::Error for Error { - fn description(&self) -> &str { - unsafe { from_utf8_unchecked(CStr::from_ptr(STRINGS[index(self)].as_ptr()).to_bytes()) } - } -} diff --git a/src/util/format/pixel.rs b/src/util/format/pixel.rs index 2c4d750..2aee470 100644 --- a/src/util/format/pixel.rs +++ b/src/util/format/pixel.rs @@ -932,7 +932,7 @@ impl fmt::Display for ParsePixelError { impl error::Error for ParsePixelError { fn description(&self) -> &str { match *self { - ParsePixelError::NulError(ref e) => e.description(), + ParsePixelError::NulError(ref e) => &e.to_string(), ParsePixelError::UnknownFormat => "unknown pixel format", } }