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

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

#7 in #reduce-boilerplate

Download history 5/week @ 2023-12-03 8/week @ 2023-12-17 5/week @ 2023-12-24 7/week @ 2024-01-07 7/week @ 2024-01-14 1/week @ 2024-02-04 11/week @ 2024-02-11 27/week @ 2024-02-18 44/week @ 2024-02-25 16/week @ 2024-03-03 40/week @ 2024-03-10 17/week @ 2024-03-17

118 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