1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-30 18:34:36 +01:00

add IntoFuture impl for Response and ResponseBuilder

This commit is contained in:
Nikolay Kim 2019-03-02 21:22:01 -08:00
parent 2d0495093c
commit b535adf637
2 changed files with 24 additions and 3 deletions

View File

@ -81,7 +81,7 @@ macro_rules! test_header {
let a: Vec<Vec<u8>> = raw.iter().map(|x| x.to_vec()).collect();
let mut req = test::TestRequest::default();
for item in a {
req = req.header(HeaderField::name(), item);
req = req.header(HeaderField::name(), item).take();
}
let req = req.finish();
let value = HeaderField::parse(&req);
@ -104,11 +104,11 @@ macro_rules! test_header {
#[test]
fn $id() {
use $crate::test;
let a: Vec<Vec<u8>> = $raw.iter().map(|x| x.to_vec()).collect();
let mut req = test::TestRequest::default();
for item in a {
req = req.header(HeaderField::name(), item);
req.header(HeaderField::name(), item);
}
let req = req.finish();
let val = HeaderField::parse(&req);

View File

@ -4,6 +4,7 @@ use std::{fmt, str};
use bytes::{BufMut, Bytes, BytesMut};
use cookie::{Cookie, CookieJar};
use futures::future::{ok, FutureResult, IntoFuture};
use futures::Stream;
use http::header::{self, HeaderName, HeaderValue};
use http::{Error as HttpError, HeaderMap, HttpTryFrom, StatusCode};
@ -276,6 +277,16 @@ impl<B: MessageBody> fmt::Debug for Response<B> {
}
}
impl IntoFuture for Response {
type Item = Response;
type Error = Error;
type Future = FutureResult<Response, Error>;
fn into_future(self) -> Self::Future {
ok(self)
}
}
pub struct CookieIter<'a> {
iter: header::ValueIter<'a, HeaderValue>,
}
@ -679,6 +690,16 @@ fn parts<'a>(
parts.as_mut()
}
impl IntoFuture for ResponseBuilder {
type Item = Response;
type Error = Error;
type Future = FutureResult<Response, Error>;
fn into_future(mut self) -> Self::Future {
ok(self.finish())
}
}
/// Helper converters
impl<I: Into<Response>, E: Into<Error>> From<Result<I, E>> for Response {
fn from(res: Result<I, E>) -> Self {