diff --git a/Cargo.lock b/Cargo.lock index 4fd0e49..c16e91f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -281,6 +281,7 @@ name = "this_algoritm" version = "0.1.0" dependencies = [ "s2", + "serde", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 2de7f68..7087583 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,4 +12,5 @@ members = [ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +serde="1" s2="0.0.12" diff --git a/types/Cargo.lock b/types/Cargo.lock deleted file mode 100644 index 202f53a..0000000 --- a/types/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "types" -version = "0.1.0" diff --git a/types/build.rs b/types/build.rs index c39d17d..f86a00b 100644 --- a/types/build.rs +++ b/types/build.rs @@ -22,58 +22,63 @@ fn main() { .unwrap(); // Write it to an array containing all words - writeln!( - &mut file, - r#"/// Static array of `Word` - pub const WORDS: &[Word] = &["# - ) - .unwrap(); + { + writeln!( + &mut file, + r#"/// Static array of `Word` +pub const WORDS: &[Word] = &["# + ) + .unwrap(); - for result in words.iter() { - writeln!(&mut file, "{result:?},").unwrap(); + for result in words.iter() { + writeln!(&mut file, "\n{result:?},").unwrap(); + } } - writeln!(&mut file, "];\n").unwrap(); // Make a mapping of all caps word to a reference to the `Word` entry - let mut word_map = phf_codegen::Map::new(); - for (idx, word) in words.iter().enumerate() { - let idx_str = format!("&WORDS[{idx}]"); - word_map.entry(word.word.to_uppercase(), &idx_str); - } - writeln!( - &mut file, - r#"/// Mapping from all caps `&str` to `&'static Word` + { + let mut word_map = phf_codegen::Map::new(); + for (idx, word) in words.iter().enumerate() { + let idx_str = format!("&WORDS[{idx}]"); + word_map.entry(word.word.to_uppercase(), &idx_str); + } + writeln!( + &mut file, + r#"/// Mapping from all caps `&str` to `&'static Word` pub static WORD_MAP: phf::Map<&'static str, &'static Word> = {};"#, - word_map.build() - ) + word_map.build() + ) + } .unwrap(); // Make a mapping of numbers to `Word`s - let word_number_to_idx = words - .iter() - .enumerate() - .map(|(idx, w)| (w.number, idx)) - .collect::>(); - - writeln!( - &mut file, - "pub const NUMBER_TO_WORD: &[&[&'static Word]] = &[" - ) - .unwrap(); - for entry in word_number_to_idx - .as_slice() - .group_by(|(number1, _idx1), (number2, _idx2)| number1 == number2) { - write!(&mut file, "\t&[",).unwrap(); + let word_number_to_idx = words + .iter() + .enumerate() + .map(|(idx, w)| (w.number, idx)) + .collect::>(); - for idx in entry.iter().map(|(_w, idx)| idx) { - write!(&mut file, "&WORDS[{idx}],").unwrap(); + writeln!( + &mut file, + "pub const NUMBER_TO_WORD: &[&[&'static Word]] = &[" + ) + .unwrap(); + for entry in word_number_to_idx + .as_slice() + .group_by(|(number1, _idx1), (number2, _idx2)| number1 == number2) + { + write!(&mut file, "\t&[",).unwrap(); + + for idx in entry.iter().map(|(_w, idx)| idx) { + write!(&mut file, "&WORDS[{idx}],").unwrap(); + } + writeln!(&mut file, "],").unwrap(); } - writeln!(&mut file, "],").unwrap(); + writeln!(&mut file, "];\n").unwrap(); } - writeln!(&mut file, "];\n").unwrap(); } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]