3 ms·
How does this relate to Tokio [0]? Why should I choose this new library instead? [0] https://github.com/tokio-rs/tokio https://github.com/tokio-rs/tokio
by mintplant 7y ago
How does this relate to Tokio [0]? Why should I choose this new library instead?
[0] https://github.com/tokio-rs/tokio https://github.com/tokio-rs/tokio
- Arnavion 7y agoIf all you needed from tokio was tokio::net, then async-std could work as a replacement for raw TCP stuff. If you needed the higher-level stuff from tokio like codecs then you'd not have those. Also, anything from the tokio ecosystem like hyper would not work with async-std. Edit: I originally had a first paragraph which was wrong. I mistakenly thought std::net::TcpListener is supposed to impl Read / Write.
- Argorak 7y ago> async-std has the equivalent of std::net::TcpListener, however it does not appear to actually impl AsyncRead / AsyncWrite. So as of now you can't do anything with it. TcpStream does impl them, at least. It does implement AsyncRead and Write, because anything with `Read` and `Write` implements it: https://docs.rs/async-std/0.99.3/async_std/io/trait.Read.html#implementors https://docs.rs/async-std/0.99.3/async_std/io/trait.Read.htm... (that's sadly a little backwards by rustdoc) The problem is that tokio has their _own_ versions of the AsyncRead and Write traits. Hyper can best be used with `async_std` through `surf`: https://github.com/rustasync/surf https://github.com/rustasync/surf
- Arnavion 7y ago>It does implement AsyncRead and Write, because anything with `Read` and `Write` implements it: https://docs.rs/async-std/0.99.3/async_std/io/trait.Read.html#implementors https://docs.rs/async-std/0.99.3/async_std/io/trait.Read.htm... (that's sadly a little backwards by rustdoc) >impl<T: AsyncRead + Unpin + ?Sized> Read for T { That's saying that anything that impls futures::AsyncRead impls async_std::io::Read. async_std::net::TcpListener does not impl AsyncRead. (Compare with TcpStream and File which do.) >Hyper can best be used with `async_std` through `surf`: https://github.com/rustasync/surf https://github.com/rustasync/surf Sure. You also don't need surf since you can directly use futures's compat executor wrapper around tokio's. The point is that you can't use stuff like hyper without the tokio executor being involved.
- jedisct1 7y agoHere's an extension trait to convert rust-std streams to tokio streams, so that they work with Hyper https://github.com/jedisct1/rust-async-std-tokio-compat https://github.com/jedisct1/rust-async-std-tokio-compat