Fix std::error::Error::description deprecation

This commit is contained in:
Zhiming Wang 2020-05-31 13:51:56 +08:00
parent 587ec66592
commit cd6c9d972b
No known key found for this signature in database
GPG Key ID: 5B58F95EC95965D8
2 changed files with 6 additions and 8 deletions

View File

@ -111,6 +111,8 @@ impl Into<c_int> for Error {
}
}
impl error::Error for Error {}
impl From<Error> for io::Error {
fn from(value: Error) -> io::Error {
io::Error::new(io::ErrorKind::Other, value)
@ -119,7 +121,9 @@ impl From<Error> 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()) }
}
}

View File

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