impl IntoFuture for HttpResponse for all body types

This commit is contained in:
Rob Ede 2022-09-26 00:16:26 +01:00
parent cc7145d41d
commit 4e7ee20bab
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
2 changed files with 16 additions and 1 deletions

View File

@ -92,6 +92,7 @@ mime = "0.3"
once_cell = "1.5"
pin-project-lite = "0.2.7"
regex = "1.5.5"
rustversion = "1"
serde = "1.0"
serde_json = "1.0"
serde_urlencoded = "0.7"

View File

@ -333,12 +333,14 @@ impl<B> From<HttpResponse<B>> for Response<B> {
#[cfg(test)]
mod response_fut_impl {
use std::{
future::Future,
future::{Future, IntoFuture},
mem,
pin::Pin,
task::{Context, Poll},
};
use actix_utils::future::{ready, Ready};
use super::*;
// Future is only implemented for BoxBody payload type because it's the most useful for making
@ -361,6 +363,18 @@ mod response_fut_impl {
)))
}
}
impl<B> IntoFuture for HttpResponse<B> {
type Output = Result<Response<B>, Error>;
type IntoFuture = Ready<Self::Output>;
fn into_future(self) -> Self::IntoFuture {
ready(match self.error.take() {
Some(err) => Err(err),
None => Ok(self.res),
})
}
}
}
impl<B> Responder for HttpResponse<B>