Reqwest: Crates that use the unstable feature can't compile with 2018 edition preview since async is a keyword

Created on 2 Jul 2018  路  6Comments  路  Source: seanmonstar/reqwest

If some code references reqwest::unstable::async it'll fail to compile:

let mut builder = ::reqwest::unstable::async::ClientBuilder::new();
19 | let mut builder = ::reqwest::unstable::async::ClientBuilder::new();
   |                                        ^^^^^ expected identifier, found reserved keyword

I don't know if this is a bit of backward-compatibility that will be fixed, or if reqwest will have to rename the module to something else.

(Trying to rename the import like use reqwest::unstable::async as reqwest_async; doesn't help either since now the error is on this use statement instead.)

Edit: #rust reminded me that raw idents exist for this purpose, so ::reqwest::unstable::r#async works fine. But maybe reqwest should rename it anyway so that everyone doesn't have to use raw idents?

Most helpful comment

My (perhaps unpopular) opinion is that the sync client should be thrown out for a strictly async API.

In sync contexts an upgrade path would be:

// 0.8.x
let mut res = reqwest::get("https://www.rust-lang.org/en-US/")?;

// 0.9.x
let mut res = reqwest::get("https://www.rust-lang.org/en-US/").wait()?;

I don't see this as nearly the insurmountable ergonomic issue that it was. Especially with the std focus of async / await / futures. Maybe it's not appropriate to do this until 0.10.x when perhaps async fn is stable syntax.


Another idea would be to keep the sync API but make async the default and stash sync at reqwest::sync::*.

All 6 comments

Sigh, that's unfortunate. The name feels like the right fit, as there is both sync and async clients...

Maybe prefix the types with Async instead?

The users who used direct references would still have to write the same number of asyncs
Before: let mut builder = ::reqwest::unstable::async::ClientBuilder::new();
After: let mut builder = ::reqwest::unstable::AsyncClientBuilder::new();

The users who didn't want to repeately type async in the first place and so used a use statement would also have to write the same number of asyncs
Before: use reqwest::unstable::async::ClientBuilder; let mut builder = ClientBuilder::new();
After: use reqwest::unstable::AsyncClientBuilder as ClientBuilder; let mut builder = ClientBuilder::new();

But the users who used wildcard imports use reqwest::unstable::async::* would have to write more Asyncs now.

My (perhaps unpopular) opinion is that the sync client should be thrown out for a strictly async API.

In sync contexts an upgrade path would be:

// 0.8.x
let mut res = reqwest::get("https://www.rust-lang.org/en-US/")?;

// 0.9.x
let mut res = reqwest::get("https://www.rust-lang.org/en-US/").wait()?;

I don't see this as nearly the insurmountable ergonomic issue that it was. Especially with the std focus of async / await / futures. Maybe it's not appropriate to do this until 0.10.x when perhaps async fn is stable syntax.


Another idea would be to keep the sync API but make async the default and stash sync at reqwest::sync::*.

@seanmonstar may be make async_impl module public meanwhile? It's not a perfect solution, but it will allow us to use reqwest with Rust 2018 until better solution arrives.

Anyone using Rust 2018 can still use reqwest by using "raw identifiers": use reqwest::unstable::r#async::Client;

thanks, that suites our needs here perfectly!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

richardanaya picture richardanaya  路  5Comments

amesgen picture amesgen  路  6Comments

samuela picture samuela  路  5Comments

nuxeh picture nuxeh  路  4Comments

theduke picture theduke  路  6Comments