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:
parent
a927e9010b
commit
71e979e023
|
@ -29,6 +29,12 @@ pub enum UserPreferences {
|
||||||
V0(v0::UserPreferencesV0)
|
V0(v0::UserPreferencesV0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for UserPreferences {
|
||||||
|
fn default() -> Self {
|
||||||
|
UserPreferences::V0(UserPreferencesV0::default())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Functionality provided by any version of user preferences
|
/// Functionality provided by any version of user preferences
|
||||||
///
|
///
|
||||||
/// See also: [`UserPreferences`]
|
/// See also: [`UserPreferences`]
|
||||||
|
@ -76,6 +82,14 @@ pub trait Preference {
|
||||||
fn into_prefstring(&self) -> String {
|
fn into_prefstring(&self) -> String {
|
||||||
BASE32_NOPAD.encode(&self.into_prefstring_bytes())
|
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 {
|
impl Preference for UserPreferences {
|
||||||
|
|
Loading…
Reference in a new issue