1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-01-18 13:51:50 +01:00

remove unsafe error transmute, upgrade failure to 0.1.2 #434

This commit is contained in:
Nikolay Kim 2018-08-01 09:42:12 -07:00
parent 58230b15b9
commit 972b008a6e
2 changed files with 4 additions and 15 deletions

View File

@ -83,7 +83,7 @@ cookie = { version="0.11", features=["percent-encode"] }
brotli2 = { version="^0.3.2", optional = true } brotli2 = { version="^0.3.2", optional = true }
flate2 = { version="^1.0.2", optional = true, default-features = false } flate2 = { version="^1.0.2", optional = true, default-features = false }
failure = "=0.1.1" failure = "^0.1.2"
# io # io
mio = "^0.6.13" mio = "^0.6.13"

View File

@ -52,7 +52,8 @@ pub struct Error {
impl Error { impl Error {
/// Deprecated way to reference the underlying response error. /// Deprecated way to reference the underlying response error.
#[deprecated( #[deprecated(
since = "0.6.0", note = "please use `Error::as_response_error()` instead" since = "0.6.0",
note = "please use `Error::as_response_error()` instead"
)] )]
pub fn cause(&self) -> &ResponseError { pub fn cause(&self) -> &ResponseError {
self.cause.as_ref() self.cause.as_ref()
@ -97,21 +98,9 @@ impl Error {
// //
// So we first downcast into that compat, to then further downcast through // So we first downcast into that compat, to then further downcast through
// the failure's Error downcasting system into the original failure. // the failure's Error downcasting system into the original failure.
//
// This currently requires a transmute. This could be avoided if failure
// provides a deref: https://github.com/rust-lang-nursery/failure/pull/213
let compat: Option<&failure::Compat<failure::Error>> = let compat: Option<&failure::Compat<failure::Error>> =
Fail::downcast_ref(self.cause.as_fail()); Fail::downcast_ref(self.cause.as_fail());
if let Some(compat) = compat { compat.and_then(|e| e.get_ref().downcast_ref())
pub struct CompatWrappedError {
error: failure::Error,
}
let compat: &CompatWrappedError =
unsafe { &*(compat as *const _ as *const CompatWrappedError) };
compat.error.downcast_ref()
} else {
None
}
} }
} }