diff --git a/libs/static_resource_derive/src/lib.rs b/libs/static_resource_derive/src/lib.rs index 770c296..f271d33 100644 --- a/libs/static_resource_derive/src/lib.rs +++ b/libs/static_resource_derive/src/lib.rs @@ -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) -> - ::futures::BoxFuture<::hyper::server::Response, Box<::std::error::Error + Send + Sync>> - { + fn get(self: Box) -> 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, _body: ::hyper::Body) -> - ::futures::BoxFuture<::hyper::server::Response, Box<::std::error::Error + Send + Sync>> - { + fn put(self: Box, _body: ::hyper::Body) -> ResponseFuture { Box::new(::futures::finished(self.method_not_allowed())) } } diff --git a/src/article_resource.rs b/src/article_resource.rs index 96de4b6..700e6cf 100644 --- a/src/article_resource.rs +++ b/src/article_resource.rs @@ -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> { + 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) -> futures::BoxFuture> { + fn get(self: Box) -> ResponseFuture { use chrono::{self, TimeZone, Local}; #[derive(BartDisplay)] @@ -111,9 +111,7 @@ impl Resource for ArticleResource { )) } - fn put(self: Box, body: hyper::Body) -> - futures::BoxFuture> - { + fn put(self: Box, body: hyper::Body) -> ResponseFuture { // TODO Check incoming Content-Type use chrono::{TimeZone, Local}; diff --git a/src/assets.rs b/src/assets.rs index e610cb3..fba9ad1 100644 --- a/src/assets.rs +++ b/src/assets.rs @@ -1,5 +1,5 @@ use futures::Future; -use web::Resource; +use web::{Resource, ResponseFuture}; #[derive(StaticResource)] #[filename = "assets/style.css"] diff --git a/src/site.rs b/src/site.rs index 4cac52b..854cb4d 100644 --- a/src/site.rs +++ b/src/site.rs @@ -71,7 +71,7 @@ impl Service for Site { type Request = Request; type Response = Response; type Error = hyper::Error; - type Future = futures::BoxFuture; + type Future = Box>; fn call(&self, req: Request) -> Self::Future { let (method, uri, _http_version, _headers, body) = req.deconstruct(); diff --git a/src/web/resource.rs b/src/web/resource.rs index cca5675..d6ad882 100644 --- a/src/web/resource.rs +++ b/src/web/resource.rs @@ -7,13 +7,14 @@ lazy_static! { static ref TEXT_PLAIN: mime::Mime = "text/plain;charset=utf-8".parse().unwrap(); } -type Error = Box; +pub type Error = Box; +pub type ResponseFuture = Box>; pub trait Resource { fn allow(&self) -> Vec; - fn head(&self) -> futures::BoxFuture; - fn get(self: Box) -> futures::BoxFuture; - fn put(self: Box, body: hyper::Body) -> futures::BoxFuture; + fn head(&self) -> ResponseFuture; + fn get(self: Box) -> ResponseFuture; + fn put(self: Box, body: hyper::Body) -> ResponseFuture; fn options(&self) -> Response { Response::new() diff --git a/src/wiki_lookup.rs b/src/wiki_lookup.rs index 5bbfc88..3fd392c 100644 --- a/src/wiki_lookup.rs +++ b/src/wiki_lookup.rs @@ -47,7 +47,7 @@ impl WikiLookup { impl Lookup for WikiLookup { type Resource = Box; type Error = Box<::std::error::Error + Send + Sync>; - type Future = futures::BoxFuture, Self::Error>; + type Future = Box, Error = Self::Error>>; fn lookup(&self, path: &str, _query: Option<&str>, _fragment: Option<&str>) -> Self::Future { assert!(path.starts_with("/"));