From 8ddd33d76d8c6f564dc2363bc41dd5554e3ffd44 Mon Sep 17 00:00:00 2001 From: Lucien Cartier-Tilet Date: Sat, 11 Jul 2020 17:47:28 +0200 Subject: [PATCH] Improve code and tests readability --- src/settings/mod.rs | 12 +++++++----- src/utils/mod.rs | 19 +++++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/settings/mod.rs b/src/settings/mod.rs index c56553d..fa52053 100644 --- a/src/settings/mod.rs +++ b/src/settings/mod.rs @@ -262,8 +262,10 @@ impl Settings { /// # Example /// /// ``` + /// # use lang_evolve_core::settings::Settings; /// use std::path::Path; - /// let s = lang_evolve_core::settings::Settings::new(); + /// + /// let s = Settings::new(); /// /// // Export to JSON /// let path_json = Path::new("./output.json"); @@ -303,14 +305,14 @@ impl Settings { let rules = self.rules.clone(); let rules: Vec = rules .iter() - .map(|x| x.update(&self.categories).unwrap()) + .map(|rule| rule.update(&self.categories).unwrap()) .collect(); Ok(rules) } /// Apply list of rules to input /// - /// The list of rules in the struct will be applied to the input `s`. If the + /// The list of rules in the struct will be applied to the input `new`. If the /// rule contains the `%` character followed by a capital letter, this marks /// a category of phonemes and should be replaced by them. For instance, we /// have: @@ -320,7 +322,7 @@ impl Settings { /// /// # Arguments /// - /// * `s` - Input to modify + /// * `new` - Input to modify /// /// # Example /// @@ -328,8 +330,8 @@ impl Settings { /// # use lang_evolve_core::settings::Settings; /// let settings = Settings::new(); /// // add some rules... - /// let input = String::new(); /// // set some input + /// let input = String::new(); /// let _output = settings.apply(input); /// ``` pub fn apply(&self, s: String) -> std::result::Result { diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 04a7d3a..2051d30 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -23,8 +23,9 @@ pub enum SettingsType { /// # Example /// /// ```no_run +/// # use lang_evolve_core::utils; /// let path = std::path::Path::new("./some/path/to/my/file.json"); -/// let content = lang_evolve_core::settings::utils::read_file(&path).unwrap(); +/// let content = utils::read_file(&path).unwrap(); /// ``` pub fn read_file(path: &Path) -> Result { let display = path.display(); @@ -53,9 +54,10 @@ pub fn read_file(path: &Path) -> Result { /// # Example /// /// ```no_run +/// # use lang_evolve_core::utils; /// let content = String::from("This is my content"); /// let path = std::path::Path::new("./path/to/my/file.txt"); -/// lang_evolve_core::settings::utils::write_file(&path, &content).unwrap(); +/// utils::write_file(&path, &content).unwrap(); /// ``` pub fn write_file(path: &Path, content: &S) -> Result<()> where @@ -98,17 +100,18 @@ where /// # Example /// /// ``` +/// # use lang_evolve_core::utils; /// let file_json = std::path::Path::new("file.json"); -/// assert_eq!(lang_evolve_core::settings::utils::SettingsType::Json, -/// lang_evolve_core::settings::utils::get_file_type(&file_json)); +/// assert_eq!(utils::SettingsType::Json, +/// utils::get_file_type(&file_json)); /// /// let file_yaml = std::path::Path::new("file.yaml"); -/// assert_eq!(lang_evolve_core::settings::utils::SettingsType::Yaml, -/// lang_evolve_core::settings::utils::get_file_type(&file_yaml)); +/// assert_eq!(utils::SettingsType::Yaml, +/// utils::get_file_type(&file_yaml)); /// /// let file_yml = std::path::Path::new("file.yml"); -/// assert_eq!(lang_evolve_core::settings::utils::SettingsType::Yaml, -/// lang_evolve_core::settings::utils::get_file_type(&file_yml)); +/// assert_eq!(utils::SettingsType::Yaml, +/// utils::get_file_type(&file_yml)); /// ``` pub fn get_file_type(path: &Path) -> SettingsType { let extension = match path.extension() {