Improve code and tests readability

This commit is contained in:
Lucien Cartier-Tilet 2020-07-11 17:47:28 +02:00
parent a8bafc072b
commit 8ddd33d76d
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA
2 changed files with 18 additions and 13 deletions

View File

@ -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<Rule> = 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<String, String> {

View File

@ -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<String> {
let display = path.display();
@ -53,9 +54,10 @@ pub fn read_file(path: &Path) -> Result<String> {
/// # 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<S>(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() {