mirror of https://github.com/fafhrd91/actix-web
feat: add &mut versions of as_response_error/as_error/HttpResponse::error
This commit is contained in:
parent
e2db4980cf
commit
081706982a
|
|
@ -17,16 +17,26 @@ pub struct Error {
|
|||
}
|
||||
|
||||
impl Error {
|
||||
/// Returns the reference to the underlying `ResponseError`.
|
||||
/// Returns a reference to the underlying `ResponseError`.
|
||||
pub fn as_response_error(&self) -> &dyn ResponseError {
|
||||
self.cause.as_ref()
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the underlying `ResponseError`.
|
||||
pub fn as_response_error_mut(&mut self) -> &mut dyn ResponseError {
|
||||
self.cause.as_mut()
|
||||
}
|
||||
|
||||
/// Similar to `as_response_error` but downcasts.
|
||||
pub fn as_error<T: ResponseError + 'static>(&self) -> Option<&T> {
|
||||
<dyn ResponseError>::downcast_ref(self.cause.as_ref())
|
||||
}
|
||||
|
||||
/// Similar to `as_response_error_mut` but downcasts.
|
||||
pub fn as_error_mut<T: ResponseError + 'static>(&mut self) -> Option<&mut T> {
|
||||
<dyn ResponseError>::downcast_mut(self.cause.as_mut())
|
||||
}
|
||||
|
||||
/// Shortcut for creating an `HttpResponse`.
|
||||
pub fn error_response(&self) -> HttpResponse {
|
||||
self.cause.error_response()
|
||||
|
|
|
|||
|
|
@ -73,12 +73,18 @@ impl<B> HttpResponse<B> {
|
|||
self.res.head_mut()
|
||||
}
|
||||
|
||||
/// The source `error` for this response
|
||||
/// Returns a reference to the source `error` for this response.
|
||||
#[inline]
|
||||
pub fn error(&self) -> Option<&Error> {
|
||||
self.error.as_ref()
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the source `error` for this response.
|
||||
#[inline]
|
||||
pub fn error_mut(&mut self) -> Option<&mut Error> {
|
||||
self.error.as_mut()
|
||||
}
|
||||
|
||||
/// Get the response status code
|
||||
#[inline]
|
||||
pub fn status(&self) -> StatusCode {
|
||||
|
|
|
|||
Loading…
Reference in New Issue