13

For my library, I want to replace async_std by smol, since the former has been deprecated in favor of the latter. This is mostly just a simple translation (different module structure, names etc.), but what I don't know is how to replace async-std's stdin. Anybody got a hint on that?

top 4 comments
sorted by: hot top controversial new old
[-] nous@programming.dev 11 points 2 weeks ago

The readme for smol has an example for stdout. I assume stdin is the same:

        let mut stdout = Unblock::new(std::io::stdout());
        io::copy(stream, &mut stdout).await?;

And there is more information about how to use it for reading/writing on the Unblock docs.

[-] KillTheMule@programming.dev 5 points 2 weeks ago

Oh yeah, the docs even mention Unblock<Stdin> explicitely. Thanks a lot!

[-] Decq@lemmy.world 0 points 2 weeks ago

I've not looked too much into it, but it seems AsyncRead/AsyncBufRead (through IoSafe) is implemented for stdin. So i think you should be able to use it like that.

[-] KillTheMule@programming.dev 1 points 2 weeks ago* (last edited 2 weeks ago)

Yeah that looks fine, thanks! It would introduce a new dependency (async_io) though, so I might go with Unblock mentioned above. Let's see what happens when I try to make the switch :)

(e) Ah I don't think this really works, I'd need to wrap it in an Async, but the docs explicitely mention not to use that with Stdin: https://docs.rs/smol/latest/smol/struct.Async.html#supported-types. Unblock it is then :)

this post was submitted on 23 Mar 2025
13 points (100.0% liked)

Rust

6738 readers
755 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 2 years ago
MODERATORS