Skip to content

Update for futures v0.3.0-alpha.15 #193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: rust
rust:
- nightly-2019-04-16
- nightly-2019-04-25

before_script: |
rustup component add rustfmt clippy
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ version = "0.1.1"

[dependencies]
cookie = { version="0.11", features = ["percent-encode"] }
futures-preview = "0.3.0-alpha.14"
futures-preview = "0.3.0-alpha.15"
fnv = "1.0.6"
http = "0.1"
http-service = "0.1.5"
http-service = "0.2.0"
pin-utils = "0.1.0-alpha.4"
route-recognizer = "0.1.12"
serde = "1.0.90"
Expand All @@ -31,7 +31,7 @@ serde_urlencoded = "0.5.5"

[dependencies.http-service-hyper]
optional = true
version = "0.1.1"
version = "0.2.0"

[dependencies.multipart]
default-features = false
Expand All @@ -46,5 +46,5 @@ hyper = ["http-service-hyper"]
basic-cookies = "0.1.3"
juniper = "0.10.0"
structopt = "0.2.15"
http-service-mock = "0.1.1"
http-service-mock = "0.2.0"
serde = { version = "1.0.90", features = ["derive"] }
2 changes: 1 addition & 1 deletion examples/body_types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(async_await, futures_api, await_macro)]
#![feature(async_await, await_macro)]

use serde::{Deserialize, Serialize};
use tide::{
Expand Down
2 changes: 1 addition & 1 deletion examples/catch_all.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(async_await, futures_api)]
#![feature(async_await)]

use tide::Context;

Expand Down
2 changes: 1 addition & 1 deletion examples/cookies.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(async_await, futures_api)]
#![feature(async_await)]

use cookie::Cookie;
use tide::{cookies::CookiesExt, middleware::CookiesMiddleware, Context};
Expand Down
2 changes: 1 addition & 1 deletion examples/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// [the Juniper book]: https://graphql-rust.github.io/

#![feature(async_await, futures_api, await_macro)]
#![feature(async_await, await_macro)]

use http::status::StatusCode;
use juniper::graphql_object;
Expand Down
2 changes: 1 addition & 1 deletion examples/messages.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(async_await, futures_api, await_macro)]
#![feature(async_await, await_macro)]

use http::status::StatusCode;
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion examples/multipart-form/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(async_await, futures_api, await_macro)]
#![feature(async_await, await_macro)]

use serde::{Deserialize, Serialize};
use std::io::Read;
Expand Down
8 changes: 4 additions & 4 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use futures::future::{self, FutureObj};
use futures::future::{self, BoxFuture};
use http_service::HttpService;
use std::sync::Arc;

Expand Down Expand Up @@ -227,7 +227,7 @@ impl<AppData: Send + Sync + 'static> App<AppData> {
.ok_or(std::io::ErrorKind::InvalidInput)?;

println!("Server is listening on: http://{}", addr);
http_service_hyper::serve(self.into_http_service(), addr);
http_service_hyper::run(self.into_http_service(), addr);
Ok(())
}
}
Expand All @@ -246,7 +246,7 @@ pub struct Server<AppData> {
impl<AppData: Sync + Send + 'static> HttpService for Server<AppData> {
type Connection = ();
type ConnectionFuture = future::Ready<Result<(), std::io::Error>>;
type Fut = FutureObj<'static, Result<http_service::Response, std::io::Error>>;
type Fut = BoxFuture<'static, Result<http_service::Response, std::io::Error>>;

fn connect(&self) -> Self::ConnectionFuture {
future::ok(())
Expand Down Expand Up @@ -289,7 +289,7 @@ mod tests {
app: &'a App<Data>,
path: &'a str,
method: http::Method,
) -> FutureObj<'a, Response> {
) -> BoxFuture<'a, Response> {
let Selection { endpoint, params } = app.router.route(path, method.clone());

let data = Arc::new(Data::default());
Expand Down
6 changes: 3 additions & 3 deletions src/endpoint.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use futures::future::{Future, FutureObj};
use futures::future::{BoxFuture, Future};

use crate::{response::IntoResponse, Context, Response};

Expand Down Expand Up @@ -58,15 +58,15 @@ pub trait Endpoint<AppData>: Send + Sync + 'static {
}

pub(crate) type DynEndpoint<AppData> =
dyn (Fn(Context<AppData>) -> FutureObj<'static, Response>) + 'static + Send + Sync;
dyn (Fn(Context<AppData>) -> BoxFuture<'static, Response>) + 'static + Send + Sync;

impl<AppData, F: Send + Sync + 'static, Fut> Endpoint<AppData> for F
where
F: Fn(Context<AppData>) -> Fut,
Fut: Future + Send + 'static,
Fut::Output: IntoResponse,
{
type Fut = FutureObj<'static, Response>;
type Fut = BoxFuture<'static, Response>;
fn call(&self, cx: Context<AppData>) -> Self::Fut {
let fut = (self)(cx);
box_async! {
Expand Down
4 changes: 3 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use core::pin::Pin;
use futures::future::Future;
use http::{HttpTryFrom, Response, StatusCode};
use http_service::Body;

use crate::response::IntoResponse;

pub(crate) type BoxTryFuture<T> = futures::future::FutureObj<'static, EndpointResult<T>>;
pub(crate) type BoxTryFuture<T> = Pin<Box<dyn Future<Output = EndpointResult<T>> + Send + 'static>>;

/// A convenient `Result` instantiation appropriate for most endpoints.
pub type EndpointResult<T = Response<Body>> = Result<T, Error>;
Expand Down
1 change: 0 additions & 1 deletion src/forms.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use futures::future::FutureObj;
use http_service::Body;
use multipart::server::Multipart;
use std::io::Cursor;
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![cfg_attr(feature = "nightly", feature(external_doc))]
#![cfg_attr(feature = "nightly", doc(include = "../README.md"))]
#![cfg_attr(test, deny(warnings))]
#![feature(futures_api, async_await, await_macro, existential_type)]
#![feature(async_await, await_macro, existential_type)]
#![allow(unused_variables)]
#![deny(nonstandard_style, rust_2018_idioms, future_incompatible)]
// TODO: Remove this after clippy bug due to async await is resolved.
Expand All @@ -18,7 +18,7 @@

macro_rules! box_async {
{$($t:tt)*} => {
FutureObj::new(Box::new(async move { $($t)* }))
::futures::future::FutureExt::boxed(async move { $($t)* })
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/middleware/cookies.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::cookies::CookieData;
use futures::future::FutureObj;
use futures::future::BoxFuture;
use http::header::HeaderValue;

use crate::{
Expand Down Expand Up @@ -30,7 +30,7 @@ impl<Data: Send + Sync + 'static> Middleware<Data> for CookiesMiddleware {
&'a self,
mut cx: Context<Data>,
next: Next<'a, Data>,
) -> FutureObj<'a, Response> {
) -> BoxFuture<'a, Response> {
box_async! {
let cookie_data = cx
.extensions_mut()
Expand Down
4 changes: 2 additions & 2 deletions src/middleware/default_headers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use futures::future::FutureObj;
use futures::future::BoxFuture;

use http::{
header::{HeaderValue, IntoHeaderName},
Expand Down Expand Up @@ -40,7 +40,7 @@ impl DefaultHeaders {
}

impl<Data: Send + Sync + 'static> Middleware<Data> for DefaultHeaders {
fn handle<'a>(&'a self, cx: Context<Data>, next: Next<'a, Data>) -> FutureObj<'a, Response> {
fn handle<'a>(&'a self, cx: Context<Data>, next: Next<'a, Data>) -> BoxFuture<'a, Response> {
box_async! {
let mut res = await!(next.run(cx));

Expand Down
4 changes: 2 additions & 2 deletions src/middleware/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use slog::{info, o, Drain};
use slog_async;
use slog_term;

use futures::future::FutureObj;
use futures::future::BoxFuture;

use crate::{
middleware::{Middleware, Next},
Expand Down Expand Up @@ -35,7 +35,7 @@ impl Default for RootLogger {
/// Stores information during request phase and logs information once the response
/// is generated.
impl<Data: Send + Sync + 'static> Middleware<Data> for RootLogger {
fn handle<'a>(&'a self, cx: Context<Data>, next: Next<'a, Data>) -> FutureObj<'a, Response> {
fn handle<'a>(&'a self, cx: Context<Data>, next: Next<'a, Data>) -> BoxFuture<'a, Response> {
box_async! {
let path = cx.uri().path().to_owned();
let method = cx.method().as_str().to_owned();
Expand Down
10 changes: 5 additions & 5 deletions src/middleware/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use futures::future::FutureObj;
use futures::future::BoxFuture;
use std::sync::Arc;

use crate::{endpoint::DynEndpoint, Context, Response};
Expand All @@ -16,14 +16,14 @@ pub trait Middleware<AppData>: 'static + Send + Sync {
&'a self,
cx: Context<AppData>,
next: Next<'a, AppData>,
) -> FutureObj<'a, Response>;
) -> BoxFuture<'a, Response>;
}

impl<Data, F> Middleware<Data> for F
where
F: Send + Sync + 'static + for<'a> Fn(Context<Data>, Next<'a, Data>) -> FutureObj<'a, Response>,
F: Send + Sync + 'static + for<'a> Fn(Context<Data>, Next<'a, Data>) -> BoxFuture<'a, Response>,
{
fn handle<'a>(&'a self, cx: Context<Data>, next: Next<'a, Data>) -> FutureObj<'a, Response> {
fn handle<'a>(&'a self, cx: Context<Data>, next: Next<'a, Data>) -> BoxFuture<'a, Response> {
(self)(cx, next)
}
}
Expand All @@ -36,7 +36,7 @@ pub struct Next<'a, AppData> {

impl<'a, AppData: 'static> Next<'a, AppData> {
/// Asynchronously execute the remaining middleware chain.
pub fn run(mut self, cx: Context<AppData>) -> FutureObj<'a, Response> {
pub fn run(mut self, cx: Context<AppData>) -> BoxFuture<'a, Response> {
if let Some((current, next)) = self.next_middleware.split_first() {
self.next_middleware = next;
current.handle(cx, self)
Expand Down
9 changes: 3 additions & 6 deletions src/router.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use fnv::FnvHashMap;
use futures::future::FutureObj;
use futures::future::{BoxFuture, FutureExt};
use http_service::Body;
use route_recognizer::{Match, Params, Router as MethodRouter};

Expand Down Expand Up @@ -33,10 +33,7 @@ impl<AppData: 'static> Router<AppData> {
self.method_map
.entry(method)
.or_insert_with(MethodRouter::new)
.add(
path,
Box::new(move |cx| FutureObj::new(Box::new(ep.call(cx)))),
)
.add(path, Box::new(move |cx| ep.call(cx).boxed()))
}

pub(crate) fn route(&self, path: &str, method: http::Method) -> Selection<'_, AppData> {
Expand All @@ -63,7 +60,7 @@ impl<AppData: 'static> Router<AppData> {
}
}

fn not_found_endpoint<Data>(_cx: Context<Data>) -> FutureObj<'static, Response> {
fn not_found_endpoint<Data>(_cx: Context<Data>) -> BoxFuture<'static, Response> {
box_async! {
http::Response::builder().status(http::StatusCode::NOT_FOUND).body(Body::empty()).unwrap()
}
Expand Down
2 changes: 1 addition & 1 deletion tests/wildcard.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(futures_api, async_await)]
#![feature(async_await)]

use futures::executor::block_on;
use http_service::Body;
Expand Down