Skip to content

Commit

Permalink
Replace await! macro with await syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed May 9, 2019
1 parent 1d5716e commit bd0a4ca
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 26 deletions.
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-25
- nightly-2019-05-09

before_script: |
rustup component add rustfmt clippy
Expand Down
10 changes: 5 additions & 5 deletions examples/body_types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(async_await, await_macro)]
#![feature(async_await)]

use serde::{Deserialize, Serialize};
use tide::{
Expand All @@ -14,25 +14,25 @@ struct Message {
}

async fn echo_string(mut cx: Context<()>) -> String {
let msg = await!(cx.body_string()).unwrap();
let msg = cx.body_string().await.unwrap();
println!("String: {}", msg);
msg
}

async fn echo_bytes(mut cx: Context<()>) -> Vec<u8> {
let msg = await!(cx.body_bytes()).unwrap();
let msg = cx.body_bytes().await.unwrap();
println!("Bytes: {:?}", msg);
msg
}

async fn echo_json(mut cx: Context<()>) -> EndpointResult {
let msg = await!(cx.body_json()).client_err()?;
let msg = cx.body_json().await.client_err()?;
println!("JSON: {:?}", msg);
Ok(response::json(msg))
}

async fn echo_form(mut cx: Context<()>) -> EndpointResult {
let msg = await!(cx.body_form())?;
let msg = cx.body_form().await?;
println!("Form: {:?}", msg);
Ok(forms::form(msg))
}
Expand Down
4 changes: 2 additions & 2 deletions 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, await_macro)]
#![feature(async_await)]

use http::status::StatusCode;
use juniper::graphql_object;
Expand Down Expand Up @@ -46,7 +46,7 @@ type Schema = juniper::RootNode<'static, Query, Mutation>;
// Finally, we'll bridge between Tide and Juniper. `GraphQLRequest` from Juniper implements
// `Deserialize`, so we use `Json` extractor to deserialize the request body.
async fn handle_graphql(mut cx: Context<Data>) -> EndpointResult {
let query: juniper::http::GraphQLRequest = await!(cx.body_json()).client_err()?;
let query: juniper::http::GraphQLRequest = cx.body_json().await.client_err()?;
let response = query.execute(&Schema::new(Query, Mutation), cx.state());
let status = if response.is_ok() {
StatusCode::OK
Expand Down
6 changes: 3 additions & 3 deletions examples/messages.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(async_await, await_macro)]
#![feature(async_await)]

use http::status::StatusCode;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -40,12 +40,12 @@ impl Database {
}

async fn new_message(mut cx: Context<Database>) -> EndpointResult<String> {
let msg = await!(cx.body_json()).client_err()?;
let msg = cx.body_json().await.client_err()?;
Ok(cx.state().insert(msg).to_string())
}

async fn set_message(mut cx: Context<Database>) -> EndpointResult<()> {
let msg = await!(cx.body_json()).client_err()?;
let msg = cx.body_json().await.client_err()?;
let id = cx.param("id").client_err()?;

if cx.state().set(id, msg) {
Expand Down
4 changes: 2 additions & 2 deletions examples/multipart-form/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(async_await, await_macro)]
#![feature(async_await)]

use serde::{Deserialize, Serialize};
use std::io::Read;
Expand All @@ -19,7 +19,7 @@ async fn upload_file(mut cx: Context<()>) -> EndpointResult {
file: None,
};

await!(cx.body_multipart())?
cx.body_multipart().await?
.foreach_entry(|mut entry| match entry.headers.name.as_str() {
"file" => {
let mut vec = Vec::new();
Expand Down
6 changes: 3 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ use crate::{
/// # Application state
///
/// ```rust, no_run, ignore
/// #![feature(async_await, futures_api, await_macro)]
/// #![feature(async_await, futures_api)]
///
/// use tide::{Context, EndpointResult, error::ResultExt, response, App};
/// use http::StatusCode;
Expand All @@ -99,7 +99,7 @@ use crate::{
/// }
///
/// async fn new_message(cx: Context<Database>) -> EndpointResult<String> {
/// let msg = await!(cx.body_json()).client_err()?;
/// let msg = cx.body_json().await.client_err()?;
///
/// let mut messages = cx.app_data().messages();
/// let id = messages.len();
Expand Down Expand Up @@ -285,7 +285,7 @@ impl<State: Sync + Send + 'static> HttpService for Server<State> {
next.run(cx)
};

Ok(await!(fut))
Ok(fut.await)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl<State> Context<State> {
/// Any I/O error encountered while reading the body is immediately returned
/// as an `Err`.
pub async fn body_bytes(&mut self) -> std::io::Result<Vec<u8>> {
await!(self.take_body().into_vec())
self.take_body().into_vec().await
}

/// Reads the entire request body into a string.
Expand All @@ -104,7 +104,7 @@ impl<State> Context<State> {
///
/// If the body cannot be interpreted as valid UTF-8, an `Err` is returned.
pub async fn body_string(&mut self) -> std::io::Result<String> {
let body_bytes = await!(self.body_bytes())?;
let body_bytes = self.body_bytes().await?;
Ok(String::from_utf8(body_bytes).map_err(|_| std::io::ErrorKind::InvalidData)?)
}

Expand All @@ -118,7 +118,7 @@ impl<State> Context<State> {
/// If the body cannot be interpreted as valid json for the target type `T`,
/// an `Err` is returned.
pub async fn body_json<T: serde::de::DeserializeOwned>(&mut self) -> std::io::Result<T> {
let body_bytes = await!(self.body_bytes())?;
let body_bytes = self.body_bytes().await?;
Ok(serde_json::from_slice(&body_bytes).map_err(|_| std::io::ErrorKind::InvalidData)?)
}

Expand Down
2 changes: 1 addition & 1 deletion src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ where
fn call(&self, cx: Context<State>) -> Self::Fut {
let fut = (self)(cx);
box_async! {
await!(fut).into_response()
fut.await.into_response()
}
}
}
4 changes: 2 additions & 2 deletions src/forms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<State: Send + Sync + 'static> ExtractForms for Context<State> {
fn body_form<T: serde::de::DeserializeOwned>(&mut self) -> BoxTryFuture<T> {
let body = self.take_body();
box_async! {
let body = await!(body.into_vec()).client_err()?;
let body = body.into_vec().await.client_err()?;
Ok(serde_urlencoded::from_bytes(&body).map_err(|e| err_fmt!("could not decode form: {}", e)).client_err()?)
}
}
Expand All @@ -36,7 +36,7 @@ impl<State: Send + Sync + 'static> ExtractForms for Context<State> {
let body = self.take_body();

box_async! {
let body = await!(body.into_vec()).client_err()?;
let body = body.into_vec().await.client_err()?;
let boundary = boundary.ok_or_else(|| err_fmt!("no boundary found")).client_err()?;
Ok(Multipart::with_body(Cursor::new(body), boundary))
}
Expand Down
2 changes: 1 addition & 1 deletion 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(async_await, await_macro, existential_type)]
#![feature(async_await, 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 Down
2 changes: 1 addition & 1 deletion src/middleware/cookies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl<Data: Send + Sync + 'static> Middleware<Data> for CookiesMiddleware {
let cookie_jar = cookie_data.content.clone();

cx.extensions_mut().insert(cookie_data);
let mut res = await!(next.run(cx));
let mut res = next.run(cx).await;
let headers = res.headers_mut();
for cookie in cookie_jar.read().unwrap().delta() {
let hv = HeaderValue::from_str(cookie.encoded().to_string().as_str());
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/default_headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl DefaultHeaders {
impl<Data: Send + Sync + 'static> Middleware<Data> for DefaultHeaders {
fn handle<'a>(&'a self, cx: Context<Data>, next: Next<'a, Data>) -> BoxFuture<'a, Response> {
box_async! {
let mut res = await!(next.run(cx));
let mut res = next.run(cx).await;

let headers = res.headers_mut();
for (key, value) in self.headers.iter() {
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl<Data: Send + Sync + 'static> Middleware<Data> for RootLogger {
let path = cx.uri().path().to_owned();
let method = cx.method().as_str().to_owned();

let res = await!(next.run(cx));
let res = next.run(cx).await;
let status = res.status();
info!(self.inner_logger, "{} {} {}", method, path, status.as_str());
res
Expand Down

0 comments on commit bd0a4ca

Please sign in to comment.