rs-sim-basic 0.1.0

Simple CLI to print similarity score of the lines.
Documentation
use std::io;
use std::process::ExitCode;

use io::BufRead;

use io::BufWriter;
use io::Write;

use rs_sim_basic::Ltsv;
use rs_sim_basic::candidates2writer;
use rs_sim_basic::lines2candidates_zip2score;

fn get_target() -> impl Fn() -> Result<String, io::Error> {
    move || {
        std::env::var("ENV_TARGET")
            .map_err(io::Error::other)
            .or_else(|_| Ok(String::default()))
    }
}

fn sub() -> Result<(), io::Error> {
    let lines = io::stdin().lock().lines();
    let target: String = get_target()()?;
    if target.is_empty() {
        return Err(io::Error::other("target ENV_TARGET unspecified"));
    }
    let ican = lines2candidates_zip2score(lines, target);
    let lcfg = Ltsv::default();
    let o = io::stdout();
    let mut ol = o.lock();
    {
        let mut bw = BufWriter::new(&mut ol);
        let cwtr = lcfg.into_candidate_writer(&mut bw);
        let f = candidates2writer(ican, cwtr);
        f()?;
        bw.flush()?;
    }
    ol.flush()
}

fn main() -> ExitCode {
    sub().map(|_| ExitCode::SUCCESS).unwrap_or_else(|e| {
        eprintln!("{e}");
        ExitCode::FAILURE
    })
}