Skip to content

Commit

Permalink
Merge pull request headzoo#111 from http-rs/futures-0.3
Browse files Browse the repository at this point in the history
Futures 0.3
  • Loading branch information
yoshuawuyts authored Nov 25, 2019
2 parents 24a3c01 + 2ff0f95 commit 380c450
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 66 deletions.
11 changes: 5 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ edition = "2018"
[features]
default = ["native-client", "middleware-logger", "encoding"]
native-client = ["curl-client", "wasm-client"]
hyper-client = ["hyper", "runtime", "runtime-raw", "runtime-tokio" ]
hyper-client = ["hyper", "hyper-tls", "native-tls", "runtime", "runtime-raw", "runtime-tokio" ]
curl-client = ["isahc"]
wasm-client = ["js-sys", "web-sys", "wasm-bindgen", "wasm-bindgen-futures"]
middleware-logger = []
encoding = ["encoding_rs"]

[dependencies]
futures-preview = { version = "0.3.0-alpha.19", features = ["compat", "io-compat"] }
futures = { version = "0.3.1", features = ["compat", "io-compat"] }
http = "0.1.17"
log = { version = "0.4.7", features = ["kv_unstable"] }
mime = "0.3.13"
Expand All @@ -36,7 +36,7 @@ url = "2.0.0"
encoding_rs = { version = "0.8.20", optional = true }

# isahc-client
isahc = { version = "0.7", optional = true, default-features = false, features = ["http2"] }
isahc = { version = "0.8", optional = true, default-features = false, features = ["http2"] }

# hyper-client
hyper = { version = "0.12.32", optional = true, default-features = false }
Expand All @@ -50,7 +50,7 @@ runtime-tokio = { version = "0.3.0-alpha.5", optional = true }
[target.'cfg(target_arch = "wasm32")'.dependencies]
js-sys = { version = "0.3.25", optional = true }
wasm-bindgen = { version = "0.2.48", optional = true }
wasm-bindgen-futures = { version = "0.3.25", features = ["futures_0_3"], optional = true }
wasm-bindgen-futures = { version = "0.4.5", optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies.web-sys]
version = "0.3.25"
Expand All @@ -72,7 +72,6 @@ features = [
]

[dev-dependencies]
async-std = "0.99.10"
async-std = { version = "1.0", features = ["attributes"] }
femme = "1.1.0"
runtime = "0.3.0-alpha.6"
serde = { version = "1.0.97", features = ["derive"] }
22 changes: 11 additions & 11 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use super::http_client::native::NativeClient;
/// # Examples
///
/// ```no_run
/// # #[runtime::main]
/// # #[async_std::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// let client = surf::Client::new();
/// let req1 = client.get("https://httpbin.org/get").recv_string();
Expand All @@ -29,7 +29,7 @@ impl Client<NativeClient> {
/// # Examples
///
/// ```no_run
/// # #[runtime::main]
/// # #[async_std::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// let client = surf::Client::new();
/// # Ok(()) }
Expand Down Expand Up @@ -62,7 +62,7 @@ impl<C: HttpClient> Client<C> {
/// # Examples
///
/// ```no_run
/// # #[runtime::main]
/// # #[async_std::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// let client = surf::Client::new();
/// let string = client.get("https://httpbin.org/get").recv_string().await?;
Expand All @@ -86,7 +86,7 @@ impl<C: HttpClient> Client<C> {
/// # Examples
///
/// ```no_run
/// # #[runtime::main]
/// # #[async_std::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// let client = surf::Client::new();
/// let string = client.head("https://httpbin.org/head").recv_string().await?;
Expand All @@ -110,7 +110,7 @@ impl<C: HttpClient> Client<C> {
/// # Examples
///
/// ```no_run
/// # #[runtime::main]
/// # #[async_std::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// let client = surf::Client::new();
/// let string = client.post("https://httpbin.org/post").recv_string().await?;
Expand All @@ -134,7 +134,7 @@ impl<C: HttpClient> Client<C> {
/// # Examples
///
/// ```no_run
/// # #[runtime::main]
/// # #[async_std::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// let client = surf::Client::new();
/// let string = client.put("https://httpbin.org/put").recv_string().await?;
Expand All @@ -158,7 +158,7 @@ impl<C: HttpClient> Client<C> {
/// # Examples
///
/// ```no_run
/// # #[runtime::main]
/// # #[async_std::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// let client = surf::Client::new();
/// let string = client.delete("https://httpbin.org/delete").recv_string().await?;
Expand All @@ -182,7 +182,7 @@ impl<C: HttpClient> Client<C> {
/// # Examples
///
/// ```no_run
/// # #[runtime::main]
/// # #[async_std::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// let client = surf::Client::new();
/// let string = client.connect("https://httpbin.org/connect").recv_string().await?;
Expand All @@ -206,7 +206,7 @@ impl<C: HttpClient> Client<C> {
/// # Examples
///
/// ```no_run
/// # #[runtime::main]
/// # #[async_std::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// let client = surf::Client::new();
/// let string = client.options("https://httpbin.org/options").recv_string().await?;
Expand All @@ -230,7 +230,7 @@ impl<C: HttpClient> Client<C> {
/// # Examples
///
/// ```no_run
/// # #[runtime::main]
/// # #[async_std::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// let client = surf::Client::new();
/// let string = client.trace("https://httpbin.org/trace").recv_string().await?;
Expand All @@ -254,7 +254,7 @@ impl<C: HttpClient> Client<C> {
/// # Examples
///
/// ```no_run
/// # #[runtime::main]
/// # #[async_std::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// let client = surf::Client::new();
/// let string = client.patch("https://httpbin.org/patch").recv_string().await?;
Expand Down
4 changes: 2 additions & 2 deletions src/http_client/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! HTTP Client Interface
use futures::future::BoxFuture;
use futures::io::AsyncRead;
use futures::io::{AsyncRead, Cursor};

use std::error::Error;
use std::fmt::{self, Debug};
Expand Down Expand Up @@ -96,7 +96,7 @@ impl From<Vec<u8>> for Body {
#[inline]
fn from(vec: Vec<u8>) -> Body {
Self {
reader: Box::new(io::Cursor::new(vec)),
reader: Box::new(Cursor::new(vec)),
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//!
//! # Examples
//! ```no_run
//! # #[runtime::main]
//! # #[async_std::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
//! let mut res = surf::get("https://httpbin.org/get").await?;
//! dbg!(res.body_string().await?);
Expand All @@ -23,7 +23,7 @@
//!
//! It's also possible to skip the intermediate `Response`, and access the response type directly.
//! ```no_run
//! # #[runtime::main]
//! # #[async_std::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
//! dbg!(surf::get("https://httpbin.org/get").recv_string().await?);
//! # Ok(()) }
Expand All @@ -32,7 +32,7 @@
//! Both sending and receiving JSON is real easy too.
//! ```no_run
//! # use serde::{Deserialize, Serialize};
//! # #[runtime::main]
//! # #[async_std::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
//! #[derive(Deserialize, Serialize)]
//! struct Ip {
Expand All @@ -53,7 +53,7 @@
//! And even creating streaming proxies is no trouble at all.
//!
//! ```no_run
//! # #[runtime::main]
//! # #[async_std::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
//! let reader = surf::get("https://img.fyi/q6YvNqP").await?;
//! let res = surf::post("https://box.rs/upload").body(reader).await?;
Expand Down
4 changes: 2 additions & 2 deletions src/middleware/logger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! # Examples
//!
//! ```
//! # #[runtime::main]
//! # #[async_std::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
//! let mut res = surf::get("https://httpbin.org/get")
//! .middleware(surf::middleware::logger::new())
Expand All @@ -29,7 +29,7 @@ use native::Logger;
/// # Examples
///
/// ```
/// # #[runtime::main]
/// # #[async_std::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// let mut res = surf::get("https://httpbin.org/get")
/// .middleware(surf::middleware::logger::new())
Expand Down
18 changes: 9 additions & 9 deletions src/one_off.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use super::Request;
/// # Examples
///
/// ```no_run
/// # #[runtime::main]
/// # #[async_std::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// let string = surf::get("https://httpbin.org/get").recv_string().await?;
/// # Ok(()) }
Expand Down Expand Up @@ -66,7 +66,7 @@ pub fn get(uri: impl AsRef<str>) -> Request<NativeClient> {
/// # Examples
///
/// ```no_run
/// # #[runtime::main]
/// # #[async_std::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// let string = surf::head("https://httpbin.org/head").recv_string().await?;
/// # Ok(()) }
Expand Down Expand Up @@ -124,7 +124,7 @@ pub fn head(uri: impl AsRef<str>) -> Request<NativeClient> {
/// # Examples
///
/// ```no_run
/// # #[runtime::main]
/// # #[async_std::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// let string = surf::post("https://httpbin.org/post").recv_string().await?;
/// # Ok(()) }
Expand Down Expand Up @@ -160,7 +160,7 @@ pub fn post(uri: impl AsRef<str>) -> Request<NativeClient> {
/// # Examples
///
/// ```no_run
/// # #[runtime::main]
/// # #[async_std::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// let string = surf::put("https://httpbin.org/put").recv_string().await?;
/// # Ok(()) }
Expand Down Expand Up @@ -191,7 +191,7 @@ pub fn put(uri: impl AsRef<str>) -> Request<NativeClient> {
/// # Examples
///
/// ```no_run
/// # #[runtime::main]
/// # #[async_std::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// let string = surf::delete("https://httpbin.org/delete").recv_string().await?;
/// # Ok(()) }
Expand Down Expand Up @@ -231,7 +231,7 @@ pub fn delete(uri: impl AsRef<str>) -> Request<NativeClient> {
/// # Examples
///
/// ```no_run
/// # #[runtime::main]
/// # #[async_std::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// let string = surf::connect("https://httpbin.org/connect").recv_string().await?;
/// # Ok(()) }
Expand Down Expand Up @@ -264,7 +264,7 @@ pub fn connect(uri: impl AsRef<str>) -> Request<NativeClient> {
/// # Examples
///
/// ```no_run
/// # #[runtime::main]
/// # #[async_std::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// let string = surf::options("https://httpbin.org/options").recv_string().await?;
/// # Ok(()) }
Expand Down Expand Up @@ -301,7 +301,7 @@ pub fn options(uri: impl AsRef<str>) -> Request<NativeClient> {
/// # Examples
///
/// ```no_run
/// # #[runtime::main]
/// # #[async_std::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// let string = surf::trace("https://httpbin.org/trace").recv_string().await?;
/// # Ok(()) }
Expand Down Expand Up @@ -344,7 +344,7 @@ pub fn trace(uri: impl AsRef<str>) -> Request<NativeClient> {
/// # Examples
///
/// ```no_run
/// # #[runtime::main]
/// # #[async_std::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// let string = surf::patch("https://httpbin.org/patch").recv_string().await?;
/// # Ok(()) }
Expand Down
Loading

0 comments on commit 380c450

Please sign in to comment.