Skip to content

Commit

Permalink
Implement ResponseError for Infallible (#2769)
Browse files Browse the repository at this point in the history
  • Loading branch information
SabrinaJewson committed May 30, 2022
1 parent 6a5b370 commit dce57a7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions actix-web/CHANGES.md
Expand Up @@ -5,6 +5,7 @@
- Add `ServiceRequest::extract()` to make it easier to use extractors when writing middlewares. [#2647]
- Add `Route::wrap()` to allow individual routes to use middleware. [#2725]
- Add `ServiceConfig::default_service()`. [#2338] [#2743]
- Implement `ResponseError` for `std::convert::Infallible`

### Fixed
- Clear connection-level data on `HttpRequest` drop. [#2742]
Expand Down
6 changes: 0 additions & 6 deletions actix-web/src/error/error.rs
Expand Up @@ -51,12 +51,6 @@ impl StdError for Error {
}
}

impl From<std::convert::Infallible> for Error {
fn from(val: std::convert::Infallible) -> Self {
match val {}
}
}

/// `Error` for any error that implements `ResponseError`
impl<T: ResponseError + 'static> From<T> for Error {
fn from(err: T) -> Error {
Expand Down
10 changes: 10 additions & 0 deletions actix-web/src/error/response_error.rs
@@ -1,6 +1,7 @@
//! `ResponseError` trait and foreign impls.

use std::{
convert::Infallible,
error::Error as StdError,
fmt,
io::{self, Write as _},
Expand Down Expand Up @@ -54,6 +55,15 @@ downcast_dyn!(ResponseError);

impl ResponseError for Box<dyn StdError + 'static> {}

impl ResponseError for Infallible {
fn status_code(&self) -> StatusCode {
match *self {}
}
fn error_response(&self) -> HttpResponse<BoxBody> {
match *self {}
}
}

#[cfg(feature = "openssl")]
impl ResponseError for actix_tls::accept::openssl::reexports::Error {}

Expand Down

0 comments on commit dce57a7

Please sign in to comment.