Skip to content

Commit

Permalink
style(misspell): Make contract explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed Page committed Oct 29, 2019
1 parent ed004e7 commit cec3ad0
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions dict/misspell/codegen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use structopt::StructOpt;

pub const DICT: &str = include_str!("../../assets/words.go");

fn parse_dict(
raw: &str,
) -> (
HashMap<&str, Vec<&str>>,
HashMap<&str, Vec<&str>>,
HashMap<&str, Vec<&str>>,
) {
struct Words<'s> {
main: HashMap<&'s str, Vec<&'s str>>,
american: HashMap<&'s str, Vec<&'s str>>,
british: HashMap<&'s str, Vec<&'s str>>,
}

fn parse_dict(raw: &str) -> Words {
let mut bad = HashMap::new();
let mut main = HashMap::new();
let mut american = HashMap::new();
Expand Down Expand Up @@ -49,7 +49,12 @@ fn parse_dict(
if !bad.is_empty() {
panic!("Failed parsing; found extra words: {:#?}", bad);
}
(main, american, british)

Words {
main,
american,
british,
}
}

fn generate<W: std::io::Write>(file: &mut W) {
Expand All @@ -63,7 +68,11 @@ fn generate<W: std::io::Write>(file: &mut W) {
writeln!(file).unwrap();
writeln!(file, "use unicase::UniCase;").unwrap();

let (main, american, british) = parse_dict(DICT);
let Words {
main,
american,
british,
} = parse_dict(DICT);

writeln!(
file,
Expand Down

0 comments on commit cec3ad0

Please sign in to comment.