Tokio server/client example?
- Dominant language
- Rust
- Stars
- 166
- Forks
- 49
- PR merge metrics
- No merged PRs in 30d
Description
Question up front: is it possible to use this crate with tokio?
I'm interested in building a library for using the Spotify API; the existing [rspotify](https://github.com/ramsayleung/rspotify) seems to be tied to tokio through its dependence on `reqwest`. I'd like this library to be executor-independent, and looking through [some](https://www.reddit.com/r/rust/comments/etsnh8/futures_and_tokio_and_asyncstd_having_duplicate/fflqhqe) [recent](https://twitter.com/stjepang/status/1241028995250114564) [discussions](http://smallcultfollowing.com/babysteps/blog/2020/03/10/async-interview-7-withoutboats/#extending-the-stdlib-with-some-key-traits) led me to this crate in particular.
I was initially a bit disappointed to see that there was no `client_tokio` example or something similar given that [it's been claimed](https://twitter.com/stjepang/status/1241028992548904960) that `async-h1` doesn't care about the server it's running with. After trying to make such an example myself, I seemed to run into a bigger issue: because tokio's `TcpStream` doesn't implement `futures::io::AsyncRead` (it implements `tokio::io::AsyncRead` instead), I think the orphan rule prevents `async-h1` from working with tokio.
Am I crazy, or is it currently impossible to use this crate with tokio?
---
EDIT: After further research, it appears like this can be accomplished using a compatibility wrapper, there's an example here: https://github.com/Nemo157/futures-tokio-compat/blob/master/src/lib.rs (which seems to have an additional benefit of not allocating the `Pin`, meaning this should be zero-cost?). I'm planning to keep working on it, if I finish up an example, is that something this project is interested in having added to the examples?
Contributor guide
Research direction
Start by reviewing the crate's existing examples and the linked futures-tokio-compat implementation to understand how Tokio's TcpStream can be used. Done means adding a Tokio client or server example that demonstrates the compatibility approach and confirms that async-h1 works with Tokio.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- networking
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100