diff --git a/src/settings/mod.rs b/src/settings/mod.rs index fa52053..cf07719 100644 --- a/src/settings/mod.rs +++ b/src/settings/mod.rs @@ -24,17 +24,17 @@ const RULESET_CURRENT_VERSION: i32 = 1; /// /// # Example /// -/// ```ignore -/// # use lang_evolve_core::settings::*; -/// # use lang_evolve_core::encode_settings; -/// use std::io::{Error, ErrorKind}; +/// ```no_run /// use std::path::Path; -/// let filetype = utils::get_file_type(Path::new("./path/to/file.json")); -/// let s = Settings::new(); +/// use lang_evolve_core::utils; +/// +/// let settings = Settings::new(); +/// let filetype = utils::get_file_type(Path::new("settings.yml")); +/// /// let content = match filetype { -/// utils::SettingsType::Yaml => encode_settings!(serde_yaml, &s).unwrap(), -/// utils::SettingsType::Json => encode_settings!(serde_json, &s).unwrap(), -/// _ => panic!("Could not encode settings"), +/// SettingsType::Yaml => encode_settings!(serde_yaml, &settings), +/// SettingsType::Json => encode_settings!(serde_json, &settings), +/// _ => String::from("Error!"), /// }; /// ``` /// @@ -64,7 +64,7 @@ macro_rules! encode_settings { /// /// # Example /// -/// ```ignore +/// ```no_run /// # use lang_evolve_core::decode_settings; /// let str = r#"{"version":"1","categories":[],"rules":[]}"#; /// let settings = decode_settings!(serde_json, str); @@ -162,9 +162,15 @@ impl Settings { /// /// # Example /// - /// ```no_run + /// ``` /// use std::path::Path; - /// use lang_evolve_core::settings::Settings; + /// # use lang_evolve_core::settings::Settings; + /// # let s = Settings::new(); + /// # for path in vec!["settings.json", "settings.yaml", "settings.yml"] { + /// # let path = Path::new(path); + /// # s.export(&path).unwrap(); + /// # } + /// /// let path_json = Path::new("settings.json"); /// let _s_json = Settings::import(&path_json).unwrap(); /// diff --git a/src/settings/rule/mod.rs b/src/settings/rule/mod.rs index 6ae92a0..96a6926 100644 --- a/src/settings/rule/mod.rs +++ b/src/settings/rule/mod.rs @@ -29,6 +29,15 @@ impl Rule { /// the input text /// * `to` - literal string that represents the regex text that should /// replaced the text matched by `from` + /// + /// # Example + /// ``` + /// # use lazy_static::lazy_static; + /// # #[path = "mod.rs"] + /// # mod rule; + /// # use rule::Rule; + /// let rule = Rule::new("ab+c*", "ab"); + /// ``` pub fn new(from: &str, to: &str) -> Self { Rule { from: Regex::new(from), diff --git a/src/settings/rule/regex_wrapper.rs b/src/settings/rule/regex_wrapper.rs index a035894..8a4a208 100644 --- a/src/settings/rule/regex_wrapper.rs +++ b/src/settings/rule/regex_wrapper.rs @@ -4,10 +4,16 @@ use std::{fmt, ops}; pub struct Regex(regex::Regex); impl Regex { + /// Create a new Regex wrapper around regex::Regex; + /// + /// # Arguments + /// + /// * `s` - string litteral from which to create the new Regex pub fn new(s: &str) -> Self { Self(regex::Regex::new(s).unwrap()) } + /// Returns a string literal representation of the Regex pub fn as_str(&self) -> &str { self.0.as_str() }