Skip to content

Commit

Permalink
first working version
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHicks committed Aug 24, 2021
1 parent 5e17a28 commit 96306f8
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 3 deletions.
110 changes: 109 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Expand Up @@ -9,3 +9,5 @@ edition = "2018"
[dependencies]
clap = "2.33.3"
color-eyre = "0.5.7"
rayon = "1.5.1"
strsim = "0.10.0"
10 changes: 8 additions & 2 deletions src/main.rs
@@ -1,6 +1,8 @@
use clap::{crate_authors, crate_version, App, Arg};
use color_eyre::eyre::{ContextCompat, Result, WrapErr};
use rayon::prelude::*;
use std::io::{self, stdin, BufRead};
use strsim::levenshtein;

fn main() {
if let Err(err) = try_main() {
Expand All @@ -27,13 +29,17 @@ fn try_main() -> Result<()> {
"could not get the target value. This is an internal error and should be reported.",
)?;

let lines: Vec<String> = stdin()
let mut lines: Vec<String> = stdin()
.lock()
.lines()
.collect::<io::Result<Vec<String>>>()
.context("could not read lines from stdin")?;

println!("{:?}", lines);
lines.par_sort_by_key(|candidate| levenshtein(target, candidate));

for candidate in lines {
println!("{}", candidate);
}

Ok(())
}

0 comments on commit 96306f8

Please sign in to comment.