interakt 0.1.1

Provides the higher order `IO` function `interact` for prototyping command line interfaces.
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented1 out of 2 items with examples
  • Size
  • Source code size: 3.29 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.04 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • mxxo/interakt
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • mxxo

Provides the higher order IO function interact for prototyping command line interfaces.

A small tutorial package for Haskell refugees adapted from this lovely walkthrough.

Interact takes a function of type Fn(String) -> String, runs it on stdin and prints the result to stdout.

Examples

cat

use interakt::interact;
use std::convert::identity;

fn main() -> std::io::Result<()> { interact(identity) }
$ cat cat.rs | cargo run --bin cat
use interakt::interact;
use std::convert::identity;

fn main() -> std::io::Result<()> { interact(identity) }

wc

# use interakt::interact;
fn main() -> std::io::Result<()> {
    let count = |s: String| -> String { format!("{}\n", s.len()) };
    interact(count)
}
$ cat cat.rs | cargo run --bin wc
109

wc -l

# use interakt::interact;
fn main() -> std::io::Result<()> {
    let count_lines = |s: String| -> String {
        format!("{}\n", s.lines().collect::<Vec<_>>().len())
    };
    interact(count_lines)
}
$ cat cat.rs | cargo run --bin wcl
4

rev

# use interakt::interact;
fn main() -> std::io::Result<()> {
    let rev_lines = |s: String| -> String {
        s.lines()
         .map(|line| line.chars().rev().collect())
         .collect::<Vec<String>>()
         .join("\n")
    };
    interact(rev_lines)
}
$ cat cat.rs | cargo run --bin rev
;tcaretni::tkaretni esu
;ytitnedi::trevnoc::dts esu

} )ytitnedi(tcaretni { >)(<tluseR::oi::dts >- )(niam nf