mirror of https://github.com/fafhrd91/actix-web
implement Responder for Option<()> and Result<(), E: Error>
This commit is contained in:
parent
91e29c0ce4
commit
13c4fb567e
|
@ -5,6 +5,7 @@
|
|||
- On Windows, an error is now returned from `HttpServer::bind()` (or TLS variants) when binding to a socket that's already in use.
|
||||
- Update `brotli` dependency to `7`.
|
||||
- Minimum supported Rust version (MSRV) is now 1.75.
|
||||
- Implemented responder for `Option<()>` and `Result<(), E: Error> to respond with `204 No Content`
|
||||
|
||||
## 4.9.0
|
||||
|
||||
|
|
|
@ -116,6 +116,17 @@ impl<R: Responder> Responder for Option<R> {
|
|||
}
|
||||
}
|
||||
|
||||
//Note see https://github.com/actix/actix-web/issues/1108 on why Responder is not implemented for ()
|
||||
impl Responder for Option<()> {
|
||||
type Body = BoxBody;
|
||||
fn respond_to(self, _req: &HttpRequest) -> HttpResponse {
|
||||
match self {
|
||||
Some(()) => HttpResponse::NoContent().finish(),
|
||||
None => HttpResponse::NotFound().finish(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<R, E> Responder for Result<R, E>
|
||||
where
|
||||
R: Responder,
|
||||
|
@ -131,6 +142,18 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
//Note see https://github.com/actix/actix-web/issues/1108 on why Responder is not implemented for ()
|
||||
impl<E: Into<Error>> Responder for Result<(), E> {
|
||||
type Body = BoxBody;
|
||||
|
||||
fn respond_to(self, _req: &HttpRequest) -> HttpResponse {
|
||||
match self {
|
||||
Ok(()) => HttpResponse::new(StatusCode::NO_CONTENT),
|
||||
Err(e) => HttpResponse::from_error(e.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: Responder> Responder for (R, StatusCode) {
|
||||
type Body = R::Body;
|
||||
|
||||
|
|
Loading…
Reference in New Issue