Crate aki_txpr_macro
source ·Expand description
the more easy to use libaki-*.
Examples
Example:
The pipe line text processing.
shell command:
aki-xcat -n -f "fixtures/target-list.txt" |\
aki-mline -e "gnu" |\
aki-stats -a --locale "en"
convert this to rust:
let (next_in, handles) = pipe_line! {
(next_in, handles);
libaki_xcat "xcat" "-n" "-f" "fixtures/target-list.txt";
libaki_mline "mline" "-e" "gnu";
libaki_stats "stats" "-a" "--locale" "en";
};
the full rust example:
fn test_02() -> anyhow::Result<String> {
use aki_txpr_macro::*;
use std::io::BufRead;
//
let next_in = runnel::medium::stdio::StdIn::default();
let handles = Vec::new();
let (next_in, handles) = pipe_line! {
(next_in, handles);
libaki_xcat "xcat" "-n" "-f" "fixtures/target-list.txt";
libaki_mline "mline" "-e" "gnu";
libaki_stats "stats" "-a" "--locale" "en";
};
// main thread
let string = {
let sout = runnel::medium::stringio::StringOut::default();
#[rustfmt::skip]
let sioe = runnel::RunnelIoeBuilder::new().pin(next_in).pout(sout).build();
for line in sioe.pin().lock().lines() {
let line_s = line?;
let line_ss = line_s.as_str();
#[rustfmt::skip]
sioe.pout().lock().write_fmt(format_args!("{}\n", line_ss))?;
}
#[rustfmt::skip]
let x = sioe.pout().lock().buffer_str().to_string();
x
};
//
for handle in handles {
let _ = handle.join();
}
//
Ok(string)
}