From 87583fc3830a4ffb833be81c4c87d670dec0003d Mon Sep 17 00:00:00 2001 From: Ben Aaron Goldberg Date: Sat, 23 Oct 2021 20:46:56 -0400 Subject: [PATCH] Change method name of Preference to better conform to standards Signed-off-by: Ben Aaron Goldberg --- src/user_preferences/mod.rs | 18 +++++++++--------- src/user_preferences/v0.rs | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/user_preferences/mod.rs b/src/user_preferences/mod.rs index dedd069..a3f16e2 100644 --- a/src/user_preferences/mod.rs +++ b/src/user_preferences/mod.rs @@ -46,7 +46,7 @@ pub trait Preference { /// crucial step to randomly selecting a pronoun set based on a user's preferences, as /// any selection is done by using a [`WeightedTable`]. All preference versions must /// implement this method. - fn into_weighted_table<'a>(&self, settings: &'a InstanceSettings) -> Result, ParseError>; + fn create_weighted_table<'a>(&self, settings: &'a InstanceSettings) -> Result, ParseError>; /// Parse a given prefstring, after it's extraction from base64 /// @@ -63,7 +63,7 @@ pub trait Preference { /// This should be done in accordance with the [prefstring specification][1]. /// /// [1]: https://fem.mint.lgbt/Emi/PronounsToday/raw/branch/main/doc/User-Preference-String-Spec.txt - fn into_prefstring_bytes(&self) -> Vec; + fn as_prefstring_bytes(&self) -> Vec; /// Parse a base64 prefstring /// @@ -79,8 +79,8 @@ pub trait Preference { /// /// This is the primary method of creating a prefstring from a `Preference` object. The /// default implementation calls the underlying [`Preference::into_prefstring_bytes()`] method. - fn into_prefstring(&self) -> String { - BASE32_NOPAD.encode(&self.into_prefstring_bytes()) + fn as_prefstring(&self) -> String { + BASE32_NOPAD.encode(&self.as_prefstring_bytes()) } /// Select a pronoun for today using this Preference's WeightedTable. @@ -98,15 +98,15 @@ pub trait Preference { Some(name) => name.as_bytes(), None => &[], }; - Ok(self.into_weighted_table(settings)?.select_today(seed)) + Ok(self.create_weighted_table(settings)?.select_today(seed)) } } impl Preference for UserPreferences { - fn into_weighted_table<'a>(&self, settings: &'a InstanceSettings) -> Result, ParseError> { + fn create_weighted_table<'a>(&self, settings: &'a InstanceSettings) -> Result, ParseError> { match self { UserPreferences::V0(pref) => pref, - }.into_weighted_table(settings) + }.create_weighted_table(settings) } fn from_prefstring_bytes(bytes: &[u8]) -> Result where Self: Sized { @@ -123,9 +123,9 @@ impl Preference for UserPreferences { } } - fn into_prefstring_bytes(&self) -> Vec { + fn as_prefstring_bytes(&self) -> Vec { match self { UserPreferences::V0(pref) => pref, - }.into_prefstring_bytes() + }.as_prefstring_bytes() } } diff --git a/src/user_preferences/v0.rs b/src/user_preferences/v0.rs index 9d06ead..805bad8 100644 --- a/src/user_preferences/v0.rs +++ b/src/user_preferences/v0.rs @@ -24,7 +24,7 @@ pub struct UserPreferencesV0 { } impl Preference for UserPreferencesV0 { - fn into_weighted_table<'a>(&self, settings: &'a InstanceSettings) -> Result, ParseError> { + fn create_weighted_table<'a>(&self, settings: &'a InstanceSettings) -> Result, ParseError> { let mut remaining_pronouns = settings.pronoun_list.iter(); let mut weighted_pronouns = HashMap::with_capacity(settings.pronoun_list.len()); @@ -118,7 +118,7 @@ impl Preference for UserPreferencesV0 { }) } - fn into_prefstring_bytes(&self) -> Vec { + fn as_prefstring_bytes(&self) -> Vec { let mut defaults_byte = 0u8; if self.default_enabled { defaults_byte |= 0b10000000; @@ -241,7 +241,7 @@ mod tests { commands: Vec::new(), }; - let table = p.into_weighted_table(&s).unwrap(); + let table = p.create_weighted_table(&s).unwrap(); let expected_table = vec![ ("she", 2), ("he", 2), @@ -271,7 +271,7 @@ mod tests { ], }; - let table = p.into_weighted_table(&s).unwrap(); + let table = p.create_weighted_table(&s).unwrap(); let expected_table = vec![ ("she", 3), ("he", 3), @@ -293,7 +293,7 @@ mod tests { ], }; - let table = p.into_weighted_table(&s).unwrap(); + let table = p.create_weighted_table(&s).unwrap(); let expected_table = vec![ ("she", 5), ("he", 4), @@ -323,7 +323,7 @@ mod tests { ], }; - let table = p.into_weighted_table(&s).unwrap(); + let table = p.create_weighted_table(&s).unwrap(); let expected_table = vec![ ("he", 9), ("they", 5), @@ -347,7 +347,7 @@ mod tests { ], }; - let err = p.into_weighted_table(&s).unwrap_err(); + let err = p.create_weighted_table(&s).unwrap_err(); assert_eq!(err, ParseError::PrefstringExceedsPronounCount); } @@ -366,7 +366,7 @@ mod tests { ], }; - let err = p.into_weighted_table(&s).unwrap_err(); + let err = p.create_weighted_table(&s).unwrap_err(); assert_eq!(err, ParseError::PrefstringExceedsPronounCount); } @@ -385,7 +385,7 @@ mod tests { ], }; - let table = p.into_weighted_table(&s).unwrap(); + let table = p.create_weighted_table(&s).unwrap(); let expected_table = vec![ ("it", 3), ];