Add the select_pronoun method to UserPreferencesV0 & impl Default for UserPreferences

Signed-off-by: Ben Aaron Goldberg <ben@benaaron.dev>
This commit is contained in:
Ben Aaron Goldberg 2021-10-23 20:31:45 -04:00
parent a927e9010b
commit 71e979e023

View file

@ -29,6 +29,12 @@ pub enum UserPreferences {
V0(v0::UserPreferencesV0)
}
impl Default for UserPreferences {
fn default() -> Self {
UserPreferences::V0(UserPreferencesV0::default())
}
}
/// Functionality provided by any version of user preferences
///
/// See also: [`UserPreferences`]
@ -76,6 +82,14 @@ pub trait Preference {
fn into_prefstring(&self) -> String {
BASE32_NOPAD.encode(&self.into_prefstring_bytes())
}
fn select_pronoun<'a>(&self, settings: &'a InstanceSettings, name: Option<&str>) -> Result<&'a Pronoun, ParseError> {
let seed = match name {
Some(name) => name.as_bytes(),
None => &[],
};
Ok(self.into_weighted_table(settings)?.select_today(seed))
}
}
impl Preference for UserPreferences {