Improve code and tests readability
This commit is contained in:
parent
a8bafc072b
commit
8ddd33d76d
@ -262,8 +262,10 @@ impl Settings {
|
|||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
|
/// # use lang_evolve_core::settings::Settings;
|
||||||
/// use std::path::Path;
|
/// use std::path::Path;
|
||||||
/// let s = lang_evolve_core::settings::Settings::new();
|
///
|
||||||
|
/// let s = Settings::new();
|
||||||
///
|
///
|
||||||
/// // Export to JSON
|
/// // Export to JSON
|
||||||
/// let path_json = Path::new("./output.json");
|
/// let path_json = Path::new("./output.json");
|
||||||
@ -303,14 +305,14 @@ impl Settings {
|
|||||||
let rules = self.rules.clone();
|
let rules = self.rules.clone();
|
||||||
let rules: Vec<Rule> = rules
|
let rules: Vec<Rule> = rules
|
||||||
.iter()
|
.iter()
|
||||||
.map(|x| x.update(&self.categories).unwrap())
|
.map(|rule| rule.update(&self.categories).unwrap())
|
||||||
.collect();
|
.collect();
|
||||||
Ok(rules)
|
Ok(rules)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Apply list of rules to input
|
/// 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
|
/// rule contains the `%` character followed by a capital letter, this marks
|
||||||
/// a category of phonemes and should be replaced by them. For instance, we
|
/// a category of phonemes and should be replaced by them. For instance, we
|
||||||
/// have:
|
/// have:
|
||||||
@ -320,7 +322,7 @@ impl Settings {
|
|||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `s` - Input to modify
|
/// * `new` - Input to modify
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
@ -328,8 +330,8 @@ impl Settings {
|
|||||||
/// # use lang_evolve_core::settings::Settings;
|
/// # use lang_evolve_core::settings::Settings;
|
||||||
/// let settings = Settings::new();
|
/// let settings = Settings::new();
|
||||||
/// // add some rules...
|
/// // add some rules...
|
||||||
/// let input = String::new();
|
|
||||||
/// // set some input
|
/// // set some input
|
||||||
|
/// let input = String::new();
|
||||||
/// let _output = settings.apply(input);
|
/// let _output = settings.apply(input);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn apply(&self, s: String) -> std::result::Result<String, String> {
|
pub fn apply(&self, s: String) -> std::result::Result<String, String> {
|
||||||
|
@ -23,8 +23,9 @@ pub enum SettingsType {
|
|||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
|
/// # use lang_evolve_core::utils;
|
||||||
/// let path = std::path::Path::new("./some/path/to/my/file.json");
|
/// 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> {
|
pub fn read_file(path: &Path) -> Result<String> {
|
||||||
let display = path.display();
|
let display = path.display();
|
||||||
@ -53,9 +54,10 @@ pub fn read_file(path: &Path) -> Result<String> {
|
|||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
|
/// # use lang_evolve_core::utils;
|
||||||
/// let content = String::from("This is my content");
|
/// let content = String::from("This is my content");
|
||||||
/// let path = std::path::Path::new("./path/to/my/file.txt");
|
/// 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<()>
|
pub fn write_file<S>(path: &Path, content: &S) -> Result<()>
|
||||||
where
|
where
|
||||||
@ -98,17 +100,18 @@ where
|
|||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
|
/// # use lang_evolve_core::utils;
|
||||||
/// let file_json = std::path::Path::new("file.json");
|
/// let file_json = std::path::Path::new("file.json");
|
||||||
/// assert_eq!(lang_evolve_core::settings::utils::SettingsType::Json,
|
/// assert_eq!(utils::SettingsType::Json,
|
||||||
/// lang_evolve_core::settings::utils::get_file_type(&file_json));
|
/// utils::get_file_type(&file_json));
|
||||||
///
|
///
|
||||||
/// let file_yaml = std::path::Path::new("file.yaml");
|
/// let file_yaml = std::path::Path::new("file.yaml");
|
||||||
/// assert_eq!(lang_evolve_core::settings::utils::SettingsType::Yaml,
|
/// assert_eq!(utils::SettingsType::Yaml,
|
||||||
/// lang_evolve_core::settings::utils::get_file_type(&file_yaml));
|
/// utils::get_file_type(&file_yaml));
|
||||||
///
|
///
|
||||||
/// let file_yml = std::path::Path::new("file.yml");
|
/// let file_yml = std::path::Path::new("file.yml");
|
||||||
/// assert_eq!(lang_evolve_core::settings::utils::SettingsType::Yaml,
|
/// assert_eq!(utils::SettingsType::Yaml,
|
||||||
/// lang_evolve_core::settings::utils::get_file_type(&file_yml));
|
/// utils::get_file_type(&file_yml));
|
||||||
/// ```
|
/// ```
|
||||||
pub fn get_file_type(path: &Path) -> SettingsType {
|
pub fn get_file_type(path: &Path) -> SettingsType {
|
||||||
let extension = match path.extension() {
|
let extension = match path.extension() {
|
||||||
|
Loading…
Reference in New Issue
Block a user