#stdin #reduce-boilerplate #utility #io #reading #async

stdinix

Utility function to reduce boilerplate for reading from stdin

2 unstable releases

0.2.0 Sep 13, 2022
0.1.0 Feb 9, 2020

#14 in #reduce-boilerplate

Download history 16/week @ 2024-06-17 12/week @ 2024-06-24 3/week @ 2024-07-01 3/week @ 2024-07-08 9/week @ 2024-07-15 13/week @ 2024-07-22 24/week @ 2024-07-29 8/week @ 2024-08-05 20/week @ 2024-08-12 5/week @ 2024-08-19 2/week @ 2024-08-26 19/week @ 2024-09-02 20/week @ 2024-09-09 16/week @ 2024-09-16 51/week @ 2024-09-23 68/week @ 2024-09-30

160 downloads per month
Used in 5 crates

MIT/Apache

3KB

Exposes a utility function to reduce boilerplate for reading from stdin.

Yes

use std::io::Result;
use stdinix::stdinix;

fn main() -> Result<()> {
    stdinix(|buf| {
        println!("{}", buf.rev().collect());

        Ok(())
    })
}

No

use std::io::Result;

fn main() -> Result<()> {
    let mut buf = String::new();
    while let Ok(true) = {
        buf.clear();
        std::io::stdin().read_line(&mut buf).map(|l| l > 0)
    } {
        println!("{}", buf.rev().collect());
    }

    Ok(())
}

Async

use std::io::Result;

#[tokio::main]
async fn main() -> Result<()> {
    let context = vec![0, 3];

    astdinix(move |line| {
        let context = context.clone();

        async move {
            println!("{} {}", line.bytes().nth(context[0]).unwrap(), line.bytes().nth(context[1]).unwrap());
            Ok(())
        }
    })
    .await
}

No runtime deps