Impl select_pronouns and add parse_prefstring to InstanceSettings
Signed-off-by: Ben Aaron Goldberg <ben@benaaron.dev>
This commit is contained in:
parent
71e979e023
commit
63dd63c230
15
src/lib.rs
15
src/lib.rs
|
@ -46,6 +46,7 @@ use std::fmt;
|
|||
|
||||
use serde::{Serialize, Deserialize, self};
|
||||
|
||||
use user_preferences::{ParseError, Preference};
|
||||
pub use weighted_table::WeightedTable;
|
||||
pub use user_preferences::UserPreferences;
|
||||
|
||||
|
@ -73,15 +74,21 @@ impl InstanceSettings {
|
|||
/// ```
|
||||
/// # use pronouns_today::InstanceSettings;
|
||||
/// # let settings = InstanceSettings::default();
|
||||
/// # let name = String::from("Sashanora");
|
||||
/// # let name = String::from("Sashanoraa");
|
||||
/// # let prefstring = String::from("todo");
|
||||
/// let pronouns = settings.parse_prefstring(Some(&prefstring)).select_pronouns(Some(&name));
|
||||
/// let pronouns = InstanceSettings::parse_prefstring(Some(&prefstring))?.select_pronouns(&settings, Some(&name));
|
||||
/// # assert_eq!(pronouns, settings.select_pronouns(Some(&name), Some(&prefstring)));
|
||||
/// ```
|
||||
pub fn select_pronouns(&self, name: Option<impl AsRef<str>>, pref_string: Option<impl AsRef<str>>) -> &str {
|
||||
todo!()
|
||||
pub fn select_pronouns(&self, name: Option<&str>, pref_string: Option<&str>) -> Result<&Pronoun, ParseError> {
|
||||
Self::parse_prefstring(pref_string)?.select_pronoun(&self, name)
|
||||
}
|
||||
|
||||
pub fn parse_prefstring(pref_string: Option<&str>) -> Result<UserPreferences, ParseError> {
|
||||
match pref_string {
|
||||
Some(pref_string) => UserPreferences::from_prefstring(pref_string),
|
||||
None => Ok(UserPreferences::default())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for InstanceSettings {
|
||||
|
|
Loading…
Reference in a new issue