Skip to content

Commit

Permalink
Merge pull request #209 from elpiel/edition-2018
Browse files Browse the repository at this point in the history
Port tower-web to Edition 2018
  • Loading branch information
lnicola authored May 20, 2019
2 parents c2fbd0b + 6d2f0e3 commit abc522f
Show file tree
Hide file tree
Showing 97 changed files with 354 additions and 437 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ matrix:
- rust: stable
- rust: nightly
# minimum rustc version
- rust: 1.29.0
- rust: 1.31.0
script: cargo build

allow_failures:
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ description = """
Web framework with a focus on removing boilerplate
"""
categories = ["asynchronous", "web-programming::http-server"]
edition = "2018"

[workspace]

Expand Down
6 changes: 5 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ as well as code.
2) Add [`features = ["async-await-preview"]`][feature] to the
`tower-web` dependency.
3) Use the necessary [nightly features] in the application.
4) Import Tokio's [`await!` macro][await].
4) Import Tokio's [`await!` macro][await]. *
5) Define [`async`][async-handler] handlers.

\* You should use nightly version prior to `nightly-2019-05-09`.
As of that version the syntax change for `.await` syntax and `tokio` 0.1
is probably not going to track nightly changes.

Support for serving data over TLS is provided with the rustls feature.
The [`rustls`](rustls) directory contains an example along with a
[Cargo.toml](rustls/Cargo.toml) file.
Expand Down
1 change: 0 additions & 1 deletion examples/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#[macro_use]
extern crate tower_web;
extern crate tokio;

use tower_web::ServiceBuilder;

Expand Down
2 changes: 1 addition & 1 deletion examples/async-await/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ name = "hyper"
path = "src/hyper.rs"

[dependencies]
tower-web = { version = "0.2.2", path = "../..", features = ["async-await-preview"] }
tower-web = { version = "0.3.7", path = "../..", features = ["async-await-preview"] }
tokio = "0.1.10"
hyper = "0.12.10"
futures = "0.1.18"
1 change: 1 addition & 0 deletions examples/async-await/rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nightly-2019-05-08
2 changes: 1 addition & 1 deletion examples/async-await/src/hyper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//!
//! curl -v http://localhost:8080/
#![feature(await_macro, async_await, futures_api)]
#![feature(await_macro, async_await)]

#[macro_use]
extern crate tower_web;
Expand Down
2 changes: 0 additions & 2 deletions examples/catch.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
extern crate futures;
#[macro_use]
extern crate tower_web;
extern crate tokio;

use futures::{Future, IntoFuture};
use tower_web::ServiceBuilder;
Expand Down
1 change: 0 additions & 1 deletion examples/derive_extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#[macro_use]
extern crate tower_web;
extern crate tokio;

use tower_web::ServiceBuilder;

Expand Down
1 change: 0 additions & 1 deletion examples/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
#[macro_use]
extern crate tower_web;
extern crate tokio;

use tower_web::ServiceBuilder;
use tokio::prelude::*;
Expand Down
1 change: 0 additions & 1 deletion examples/html_handlebars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
extern crate env_logger;
#[macro_use]
extern crate tower_web;
extern crate tokio;

use tower_web::ServiceBuilder;
use tower_web::view::Handlebars;
Expand Down
1 change: 0 additions & 1 deletion examples/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#[macro_use]
extern crate tower_web;
extern crate tokio;

#[macro_use]
extern crate serde_json;
Expand Down
2 changes: 0 additions & 2 deletions examples/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
/// curl -v http://localhost:8080/
extern crate env_logger;
extern crate flate2;
#[macro_use]
extern crate tower_web;
extern crate tokio;

use tower_web::ServiceBuilder;
use tower_web::middleware::deflate::DeflateMiddleware;
Expand Down
2 changes: 1 addition & 1 deletion examples/static_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#[macro_use]
extern crate tower_web;
extern crate tokio;


use std::{io, path::PathBuf};
use tokio::{fs::File, prelude::Future};
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/async_await.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::future::Future as StdFuture;
/// This bridges async/await with stable futures.
pub fn async_to_box_future_send<T>(
future: T,
) -> Box<Future<Item = T::Output, Error = ::Error> + Send>
) -> Box<impl Future<Item = T::Output, Error = crate::Error> + Send>
where
T: StdFuture + Send + 'static,
{
Expand Down
8 changes: 4 additions & 4 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::collections::HashMap;
use std::hash::{BuildHasherDefault, Hasher};
use std::fmt;

type AnyMap = HashMap<TypeId, Box<Any + Send + Sync>, BuildHasherDefault<IdHasher>>;
type AnyMap = HashMap<TypeId, Box<dyn Any + Send + Sync>, BuildHasherDefault<IdHasher>>;

#[derive(Debug, Default)]
struct IdHasher(u64);
Expand Down Expand Up @@ -50,7 +50,7 @@ impl ConfigBuilder {
}

impl fmt::Debug for ConfigBuilder {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("ConfigBuilder")
.finish()
}
Expand All @@ -71,13 +71,13 @@ impl Config {
self.inner
.get(&TypeId::of::<T>())
.and_then(|boxed| {
(&**boxed as &Any).downcast_ref()
(&**boxed as &dyn Any).downcast_ref()
})
}
}

impl fmt::Debug for Config {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Config")
.finish()
}
Expand Down
6 changes: 3 additions & 3 deletions src/error/catch.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use error::Error;
use crate::error::Error;
use serde_json;
use response::Serializer;
use util::BufStream;
use crate::response::Serializer;
use crate::util::BufStream;

use futures::{future, Future, IntoFuture};
use http;
Expand Down
6 changes: 3 additions & 3 deletions src/error/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl error::Error for Error {
}

impl fmt::Debug for Error {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("Error")
.field("kind", &self.kind)
.field("title", &self.title)
Expand All @@ -150,7 +150,7 @@ impl fmt::Debug for Error {

impl fmt::Display for Error {
#[allow(deprecated)] // .cause() is deprecated on nightly
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
fmt,
"[{}] {}",
Expand Down Expand Up @@ -302,7 +302,7 @@ impl ErrorKind {
}

impl fmt::Debug for ErrorKind {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.kind {
BadRequest => "ErrorKind::BadRequest",
Unauthorized => "ErrorKind::Unauthorized",
Expand Down
14 changes: 7 additions & 7 deletions src/error/map.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use http::status::StatusCode;
use util::BufStream;
use crate::util::BufStream;

use futures::{Future, Poll};

Expand All @@ -16,7 +16,7 @@ pub struct Map<T> {
#[derive(Debug)]
enum State<T> {
Inner(T),
Immediate(Option<::Error>),
Immediate(Option<crate::Error>),
}

impl<T> Map<T> {
Expand All @@ -35,7 +35,7 @@ impl<T> Map<T> {
/// Create a neew `Map` instance that is in the error state.
///
/// The instance will yield `error` immediately when it is used.
pub fn immediate(error: ::Error) -> Map<T> {
pub fn immediate(error: crate::Error) -> Map<T> {
Map {
inner: State::Immediate(Some(error)),
}
Expand All @@ -44,27 +44,27 @@ impl<T> Map<T> {

impl<T: Future> Future for Map<T> {
type Item = T::Item;
type Error = ::Error;
type Error = crate::Error;

fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
use self::State::*;

match self.inner {
Inner(ref mut f) => f.poll().map_err(|_| ::Error::from(StatusCode::INTERNAL_SERVER_ERROR)),
Inner(ref mut f) => f.poll().map_err(|_| crate::Error::from(StatusCode::INTERNAL_SERVER_ERROR)),
Immediate(ref mut e) => Err(e.take().unwrap()),
}
}
}

impl<T: BufStream> BufStream for Map<T> {
type Item = T::Item;
type Error = ::Error;
type Error = crate::Error;

fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
use self::State::*;

match self.inner {
Inner(ref mut f) => f.poll().map_err(|_| ::Error::from(StatusCode::INTERNAL_SERVER_ERROR)),
Inner(ref mut f) => f.poll().map_err(|_| crate::Error::from(StatusCode::INTERNAL_SERVER_ERROR)),
Immediate(ref mut e) => Err(e.take().unwrap()),
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/error/never.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use error::Error;
use crate::error::Error;

use std::error;
use std::fmt;
Expand All @@ -16,13 +16,13 @@ impl From<Never> for Error {
}

impl fmt::Debug for Never {
fn fmt(&self, _f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {}
}
}

impl fmt::Display for Never {
fn fmt(&self, _f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {}
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/extract/bytes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use codegen::CallSite;
use extract::{Context, Error, Extract, ExtractFuture};
use util::buf_stream::{self, BufStream};
use crate::codegen::CallSite;
use crate::extract::{Context, Error, Extract, ExtractFuture};
use crate::util::buf_stream::{self, BufStream};

use futures::{Future, Poll};

Expand All @@ -19,8 +19,8 @@ enum State<T, B> {
impl<B: BufStream> Extract<B> for Vec<u8> {
type Future = ExtractBytes<Self, B>;

fn extract(ctx: &Context) -> Self::Future {
use codegen::Source::*;
fn extract(ctx: &Context<'_>) -> Self::Future {
use crate::codegen::Source::*;

match ctx.callsite().source() {
Capture(idx) => {
Expand Down Expand Up @@ -58,8 +58,8 @@ impl<B: BufStream> Extract<B> for Vec<u8> {
}
}

fn extract_body(ctx: &Context, body: B) -> Self::Future {
use codegen::Source::*;
fn extract_body(ctx: &Context<'_>, body: B) -> Self::Future {
use crate::codegen::Source::*;

match ctx.callsite().source() {
Body => {
Expand Down
8 changes: 4 additions & 4 deletions src/extract/context.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use codegen::CallSite;
use config::Config;
use routing::{Captures, RouteMatch};
use crate::codegen::CallSite;
use crate::config::Config;
use crate::routing::{Captures, RouteMatch};

use http::Request;

Expand All @@ -23,7 +23,7 @@ pub struct Context<'a> {
impl<'a> Context<'a> {
// Used as part of codegen, but not part of the public API.
#[doc(hidden)]
pub fn new(route_match: &'a RouteMatch, callsite: &'a CallSite) -> Context<'a> {
pub fn new(route_match: &'a RouteMatch<'_>, callsite: &'a CallSite) -> Context<'a> {
let request = route_match.request();
let captures = route_match.captures();
let config = route_match.config();
Expand Down
12 changes: 6 additions & 6 deletions src/extract/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct Error {
enum Kind {
Missing,
Invalid(String),
Web(::Error),
Web(crate::Error),
}

impl Error {
Expand Down Expand Up @@ -45,21 +45,21 @@ impl Error {
}

pub(crate) fn internal_error() -> Error {
::Error::from(StatusCode::BAD_REQUEST).into()
crate::Error::from(StatusCode::BAD_REQUEST).into()
}
}

impl From<Error> for ::Error {
impl From<Error> for crate::Error {
fn from(err: Error) -> Self {
match err.kind {
Missing | Invalid(_) => ::Error::from(StatusCode::BAD_REQUEST),
Missing | Invalid(_) => crate::Error::from(StatusCode::BAD_REQUEST),
Web(err) => err,
}
}
}

impl From<::Error> for Error {
fn from(err: ::Error) -> Self {
impl From<crate::Error> for Error {
fn from(err: crate::Error) -> Self {
Error { kind: Web(err) }
}
}
6 changes: 3 additions & 3 deletions src/extract/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
use http::Request;

use extract::{Context, Error, Extract, Immediate};
use util::BufStream;
use crate::extract::{Context, Error, Extract, Immediate};
use crate::util::BufStream;

impl<B: BufStream> Extract<B> for Request<()> {
type Future = Immediate<Self>;

fn extract(ctx: &Context) -> Self::Future {
fn extract(ctx: &Context<'_>) -> Self::Future {
let request = Request::builder()
.version(ctx.request().version())
.method(ctx.request().method())
Expand Down
Loading

0 comments on commit abc522f

Please sign in to comment.