From cec3ad07f1b3f5bf659e7d895ebdf9438c23e3f9 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 29 Oct 2019 07:55:50 -0600 Subject: [PATCH] style(misspell): Make contract explicit --- dict/misspell/codegen/src/main.rs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/dict/misspell/codegen/src/main.rs b/dict/misspell/codegen/src/main.rs index a9b9222..df957f2 100644 --- a/dict/misspell/codegen/src/main.rs +++ b/dict/misspell/codegen/src/main.rs @@ -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(); @@ -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(file: &mut W) { @@ -63,7 +68,11 @@ fn generate(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,