Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ResponseError for Infallible #2769

Merged
merged 2 commits into from May 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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