From bae1d86544ba3cdf6336720c23b36559323fbe91 Mon Sep 17 00:00:00 2001 From: Lucien Cartier-Tilet Date: Sun, 29 Mar 2020 18:10:45 +0200 Subject: [PATCH] Switched from Vectors to HashMaps, need to update docs --- src/settings/mod.rs | 9 +++++---- src/settings/regex_wrapper.rs | 7 +++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/settings/mod.rs b/src/settings/mod.rs index 8ed524c..2284d9c 100644 --- a/src/settings/mod.rs +++ b/src/settings/mod.rs @@ -91,6 +91,7 @@ macro_rules! decode_settings { }; } +use std::collections::HashMap; /// Representation of the software’s settings /// /// This struct represents all the settings the software has to follow @@ -116,7 +117,7 @@ pub struct Settings { /// phonemes. It is currently not possible to have more than one /// character to be considered as one sound. #[serde(default)] - pub categories: Vec<(String, String)>, + pub categories: HashMap, /// Soundchange rules /// @@ -124,7 +125,7 @@ pub struct Settings { /// a regex to be matched while the second represents the change /// to be made to the input data. #[serde(default)] - pub rules: Vec<(Regex, Regex)>, + pub rules: HashMap, } /// Representation inside the crate of LangEvolve’s settings. @@ -148,8 +149,8 @@ impl Settings { pub fn new() -> Self { Self { version: Self::get_ruleset_version(), - categories: Vec::new(), - rules: Vec::new(), + categories: HashMap::new(), + rules: HashMap::new(), } } diff --git a/src/settings/regex_wrapper.rs b/src/settings/regex_wrapper.rs index b186943..f238a90 100644 --- a/src/settings/regex_wrapper.rs +++ b/src/settings/regex_wrapper.rs @@ -31,6 +31,13 @@ impl Regex { } } +use std::hash::{Hash, Hasher}; +impl Hash for Regex { + fn hash(&self, state: &mut H) { + self.0.as_str().hash(state); + } +} + impl ops::Deref for Regex { type Target = regex::Regex; fn deref(&self) -> ®ex::Regex {