From 4e7ee20bab00064b02a665a4cd028cf74036e911 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Mon, 26 Sep 2022 00:16:26 +0100 Subject: [PATCH] impl IntoFuture for HttpResponse for all body types --- actix-web/Cargo.toml | 1 + actix-web/src/response/response.rs | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/actix-web/Cargo.toml b/actix-web/Cargo.toml index c7b54bd46..f32ccc14e 100644 --- a/actix-web/Cargo.toml +++ b/actix-web/Cargo.toml @@ -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" diff --git a/actix-web/src/response/response.rs b/actix-web/src/response/response.rs index ead8badba..13fa653b7 100644 --- a/actix-web/src/response/response.rs +++ b/actix-web/src/response/response.rs @@ -333,12 +333,14 @@ impl From> for Response { #[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 IntoFuture for HttpResponse { + type Output = Result, Error>; + type IntoFuture = Ready; + + fn into_future(self) -> Self::IntoFuture { + ready(match self.error.take() { + Some(err) => Err(err), + None => Ok(self.res), + }) + } + } } impl Responder for HttpResponse