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

View file

@ -10,7 +10,7 @@ use assets::{StyleCss, ScriptJs};
use models;
use site::Layout;
use state::State;
use web::Resource;
use web::{Resource, ResponseFuture};
lazy_static! {
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]
}
fn head(&self) -> futures::BoxFuture<Response, Box<::std::error::Error + Send + Sync>> {
fn head(&self) -> ResponseFuture {
Box::new(futures::finished(Response::new()
.with_status(hyper::StatusCode::Ok)
.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};
#[derive(BartDisplay)]
@ -111,9 +111,7 @@ impl Resource for ArticleResource {
))
}
fn put(self: Box<Self>, body: hyper::Body) ->
futures::BoxFuture<Response, Box<::std::error::Error + Send + Sync>>
{
fn put(self: Box<Self>, body: hyper::Body) -> ResponseFuture {
// TODO Check incoming Content-Type
use chrono::{TimeZone, Local};

View file

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

View file

@ -71,7 +71,7 @@ impl Service for Site {
type Request = Request;
type Response = Response;
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 {
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();
}
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 {
fn allow(&self) -> Vec<hyper::Method>;
fn head(&self) -> futures::BoxFuture<server::Response, Error>;
fn get(self: Box<Self>) -> futures::BoxFuture<server::Response, Error>;
fn put(self: Box<Self>, body: hyper::Body) -> futures::BoxFuture<server::Response, Error>;
fn head(&self) -> ResponseFuture;
fn get(self: Box<Self>) -> ResponseFuture;
fn put(self: Box<Self>, body: hyper::Body) -> ResponseFuture;
fn options(&self) -> Response {
Response::new()

View file

@ -47,7 +47,7 @@ impl WikiLookup {
impl Lookup for WikiLookup {
type Resource = Box<Resource + 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 {
assert!(path.starts_with("/"));