Remove all usage of futures::BoxFuture, which is deprecated

This commit is contained in:
Magnus Hoff 2017-09-17 12:08:42 +02:00
parent 551cc22383
commit 88eda46d95
6 changed files with 15 additions and 22 deletions

View file

@ -71,9 +71,7 @@ pub fn static_resource(input: TokenStream) -> TokenStream {
vec![Options, Head, Get] vec![Options, Head, Get]
} }
fn head(&self) -> fn head(&self) -> ResponseFuture {
::futures::BoxFuture<::hyper::server::Response, Box<::std::error::Error + Send + Sync>>
{
Box::new(::futures::finished(::hyper::server::Response::new() Box::new(::futures::finished(::hyper::server::Response::new()
.with_status(::hyper::StatusCode::Ok) .with_status(::hyper::StatusCode::Ok)
.with_header(::hyper::header::ContentType( .with_header(::hyper::header::ContentType(
@ -87,9 +85,7 @@ pub fn static_resource(input: TokenStream) -> TokenStream {
)) ))
} }
fn get(self: Box<Self>) -> fn get(self: Box<Self>) -> ResponseFuture {
::futures::BoxFuture<::hyper::server::Response, Box<::std::error::Error + Send + Sync>>
{
let body = include_bytes!(#abs_filename); let body = include_bytes!(#abs_filename);
Box::new(self.head().map(move |head| Box::new(self.head().map(move |head|
@ -99,9 +95,7 @@ pub fn static_resource(input: TokenStream) -> TokenStream {
)) ))
} }
fn put(self: Box<Self>, _body: ::hyper::Body) -> fn put(self: Box<Self>, _body: ::hyper::Body) -> ResponseFuture {
::futures::BoxFuture<::hyper::server::Response, Box<::std::error::Error + Send + Sync>>
{
Box::new(::futures::finished(self.method_not_allowed())) Box::new(::futures::finished(self.method_not_allowed()))
} }
} }

View file

@ -10,7 +10,7 @@ use assets::{StyleCss, ScriptJs};
use models; use models;
use site::Layout; use site::Layout;
use state::State; use state::State;
use web::Resource; use web::{Resource, ResponseFuture};
lazy_static! { lazy_static! {
static ref TEXT_HTML: mime::Mime = "text/html;charset=utf-8".parse().unwrap(); static ref TEXT_HTML: mime::Mime = "text/html;charset=utf-8".parse().unwrap();
@ -69,14 +69,14 @@ impl Resource for ArticleResource {
vec![Options, Head, Get, Put] vec![Options, Head, Get, Put]
} }
fn head(&self) -> futures::BoxFuture<Response, Box<::std::error::Error + Send + Sync>> { fn head(&self) -> ResponseFuture {
Box::new(futures::finished(Response::new() Box::new(futures::finished(Response::new()
.with_status(hyper::StatusCode::Ok) .with_status(hyper::StatusCode::Ok)
.with_header(ContentType(TEXT_HTML.clone())) .with_header(ContentType(TEXT_HTML.clone()))
)) ))
} }
fn get(self: Box<Self>) -> futures::BoxFuture<Response, Box<::std::error::Error + Send + Sync>> { fn get(self: Box<Self>) -> ResponseFuture {
use chrono::{self, TimeZone, Local}; use chrono::{self, TimeZone, Local};
#[derive(BartDisplay)] #[derive(BartDisplay)]
@ -111,9 +111,7 @@ impl Resource for ArticleResource {
)) ))
} }
fn put(self: Box<Self>, body: hyper::Body) -> fn put(self: Box<Self>, body: hyper::Body) -> ResponseFuture {
futures::BoxFuture<Response, Box<::std::error::Error + Send + Sync>>
{
// TODO Check incoming Content-Type // TODO Check incoming Content-Type
use chrono::{TimeZone, Local}; use chrono::{TimeZone, Local};

View file

@ -1,5 +1,5 @@
use futures::Future; use futures::Future;
use web::Resource; use web::{Resource, ResponseFuture};
#[derive(StaticResource)] #[derive(StaticResource)]
#[filename = "assets/style.css"] #[filename = "assets/style.css"]

View file

@ -71,7 +71,7 @@ impl Service for Site {
type Request = Request; type Request = Request;
type Response = Response; type Response = Response;
type Error = hyper::Error; type Error = hyper::Error;
type Future = futures::BoxFuture<Response, Self::Error>; type Future = Box<futures::Future<Item = Response, Error = Self::Error>>;
fn call(&self, req: Request) -> Self::Future { fn call(&self, req: Request) -> Self::Future {
let (method, uri, _http_version, _headers, body) = req.deconstruct(); let (method, uri, _http_version, _headers, body) = req.deconstruct();

View file

@ -7,13 +7,14 @@ lazy_static! {
static ref TEXT_PLAIN: mime::Mime = "text/plain;charset=utf-8".parse().unwrap(); static ref TEXT_PLAIN: mime::Mime = "text/plain;charset=utf-8".parse().unwrap();
} }
type Error = Box<std::error::Error + Send + Sync>; pub type Error = Box<std::error::Error + Send + Sync>;
pub type ResponseFuture = Box<futures::Future<Item = server::Response, Error = Error>>;
pub trait Resource { pub trait Resource {
fn allow(&self) -> Vec<hyper::Method>; fn allow(&self) -> Vec<hyper::Method>;
fn head(&self) -> futures::BoxFuture<server::Response, Error>; fn head(&self) -> ResponseFuture;
fn get(self: Box<Self>) -> futures::BoxFuture<server::Response, Error>; fn get(self: Box<Self>) -> ResponseFuture;
fn put(self: Box<Self>, body: hyper::Body) -> futures::BoxFuture<server::Response, Error>; fn put(self: Box<Self>, body: hyper::Body) -> ResponseFuture;
fn options(&self) -> Response { fn options(&self) -> Response {
Response::new() Response::new()

View file

@ -47,7 +47,7 @@ impl WikiLookup {
impl Lookup for WikiLookup { impl Lookup for WikiLookup {
type Resource = Box<Resource + Send + Sync>; type Resource = Box<Resource + Send + Sync>;
type Error = Box<::std::error::Error + Send + Sync>; type Error = Box<::std::error::Error + Send + Sync>;
type Future = futures::BoxFuture<Option<Self::Resource>, Self::Error>; type Future = Box<Future<Item = Option<Self::Resource>, Error = Self::Error>>;
fn lookup(&self, path: &str, _query: Option<&str>, _fragment: Option<&str>) -> Self::Future { fn lookup(&self, path: &str, _query: Option<&str>, _fragment: Option<&str>) -> Self::Future {
assert!(path.starts_with("/")); assert!(path.starts_with("/"));