Crates.io | rsteract |
lib.rs | rsteract |
version | 0.1.0 |
source | src |
created_at | 2022-07-07 21:53:06.357912 |
updated_at | 2022-07-07 21:53:06.357912 |
description | From stdin to String and back to stdout |
homepage | https://github.com/alepez/rsteract |
repository | https://github.com/alepez/rsteract |
max_upload_size | |
id | 621502 |
size | 15,574 |
A clone of Haskell interact function.
The interact function takes a function of type Fn(String) -> String
as its argument.
The entire input from the standard input device is passed to this function as its argument, and the resulting string is output on the standard output device.
If this is your_program
:
use rsteract::stdio::interact;
fn main() -> Result<(), std::io::Error> {
interact(|x| x.chars().rev().collect())
}
❯ echo 1234 | your_program
4321
This crate also provide a generic version for Read
and Write
traits.
Competitive programming, when you need to quickly write code to read from stdin and write to stdout.
Feel free to copy this your code in your program, if using external crates is not an option.