Skip to content

Commit dce57a7

Browse files
Implement ResponseError for Infallible (#2769)
1 parent 6a5b370 commit dce57a7

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

actix-web/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Add `ServiceRequest::extract()` to make it easier to use extractors when writing middlewares. [#2647]
66
- Add `Route::wrap()` to allow individual routes to use middleware. [#2725]
77
- Add `ServiceConfig::default_service()`. [#2338] [#2743]
8+
- Implement `ResponseError` for `std::convert::Infallible`
89

910
### Fixed
1011
- Clear connection-level data on `HttpRequest` drop. [#2742]

actix-web/src/error/error.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@ impl StdError for Error {
5151
}
5252
}
5353

54-
impl From<std::convert::Infallible> for Error {
55-
fn from(val: std::convert::Infallible) -> Self {
56-
match val {}
57-
}
58-
}
59-
6054
/// `Error` for any error that implements `ResponseError`
6155
impl<T: ResponseError + 'static> From<T> for Error {
6256
fn from(err: T) -> Error {

actix-web/src/error/response_error.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! `ResponseError` trait and foreign impls.
22
33
use std::{
4+
convert::Infallible,
45
error::Error as StdError,
56
fmt,
67
io::{self, Write as _},
@@ -54,6 +55,15 @@ downcast_dyn!(ResponseError);
5455

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

58+
impl ResponseError for Infallible {
59+
fn status_code(&self) -> StatusCode {
60+
match *self {}
61+
}
62+
fn error_response(&self) -> HttpResponse<BoxBody> {
63+
match *self {}
64+
}
65+
}
66+
5767
#[cfg(feature = "openssl")]
5868
impl ResponseError for actix_tls::accept::openssl::reexports::Error {}
5969

0 commit comments

Comments
 (0)