diff --git a/src/lib.rs b/src/lib.rs index 359c69c..9c2c7eb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,6 +8,7 @@ //! ## Basic Usage //! //! ``` +//! # use pronouns_today::user_preferences::ParseError; //! use pronouns_today::InstanceSettings; //! //! let instance_settings = InstanceSettings::default(); // Or load from a config file @@ -15,9 +16,10 @@ //! // When you receive a request //! let user_name = Some("Emi"); //! let user_prefstr = Some("acaqqbykawbag"); -//! let pronouns = instance_settings.select_pronouns(user_name, user_prefstr); +//! let pronouns = instance_settings.select_pronouns(user_name, user_prefstr)?; //! //! println!("Your pronouns are: {}", pronouns); +//! # Ok::<(), ParseError>(()) //! ``` //! //! ## Advanced Usage @@ -74,12 +76,15 @@ impl InstanceSettings { /// This is shorthand for /// /// ``` + /// # use crate::pronouns_today::user_preferences::Preference; + /// # use pronouns_today::user_preferences::ParseError; /// # use pronouns_today::InstanceSettings; /// # let settings = InstanceSettings::default(); /// # let name = String::from("Sashanoraa"); - /// # let prefstring = String::from("todo"); - /// let pronouns = InstanceSettings::parse_prefstring(Some(&prefstring))?.select_pronouns(&settings, Some(&name)); + /// # let prefstring = String::from("acaqebicadbqaaa"); + /// let pronouns = InstanceSettings::parse_prefstring(Some(&prefstring))?.select_pronoun(&settings, Some(&name)); /// # assert_eq!(pronouns, settings.select_pronouns(Some(&name), Some(&prefstring))); + /// # Ok::<(), ParseError>(()) /// ``` pub fn select_pronouns(&self, name: Option<&str>, pref_string: Option<&str>) -> Result<&Pronoun, ParseError> { Self::parse_prefstring(pref_string)?.select_pronoun(&self, name) diff --git a/src/user_preferences/mod.rs b/src/user_preferences/mod.rs index 0870554..bd1f367 100644 --- a/src/user_preferences/mod.rs +++ b/src/user_preferences/mod.rs @@ -100,10 +100,14 @@ pub trait Preference { /// Is shorthand for /// /// ``` - /// # use pronouns_today::InstanceSettings; + /// # use pronouns_today::user_preferences::ParseError; + /// # use pronouns_today::{InstanceSettings, UserPreferences}; + /// # use crate::pronouns_today::user_preferences::Preference; /// # let settings = InstanceSettings::default(); /// # let seed = &[]; - /// self.into_weighted_table(settings)?.select_today(seed) + /// # let prefs = UserPreferences::default(); + /// prefs.create_weighted_table(&settings)?.select_today(seed); + /// # Ok::<(), ParseError>(()) /// ``` fn select_pronoun<'a>(&self, settings: &'a InstanceSettings, name: Option<&str>) -> Result<&'a Pronoun, ParseError> { let seed = match name { diff --git a/src/user_preferences/v0.rs b/src/user_preferences/v0.rs index 324baa3..5a4e879 100644 --- a/src/user_preferences/v0.rs +++ b/src/user_preferences/v0.rs @@ -306,7 +306,7 @@ mod tests { fn check_table(actual: WeightedTable<&Pronoun>, expected: Vec<(&str, u8)>) { let actual_simplified = actual.weights() .into_iter() - .filter(|(pronoun, weight)| **weight > 0) + .filter(|(_, weight)| **weight > 0) .map(|(pronoun, weight)| (pronoun.subject_pronoun.as_str(), *weight)) .collect::>(); let expected_owned = expected.into_iter() @@ -362,6 +362,7 @@ mod tests { ("they", 3), ("it", 3), ]; + check_table(table, expected_table); } #[test]