[lib] fix clippy warnings

Signed-off-by: Ben Aaron Goldberg <ben@benaaron.dev>
This commit is contained in:
Ben Aaron Goldberg 2021-11-29 17:52:03 -05:00
parent a853d8796a
commit 32a83243fa
4 changed files with 8 additions and 6 deletions

View file

@ -40,6 +40,8 @@
//!
//! [up]: UserPreferences
#![allow(clippy::tabs_in_doc_comments)]
pub mod user_preferences;
pub mod util;
mod weighted_table;
@ -87,7 +89,7 @@ impl InstanceSettings {
/// # 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)
Self::parse_prefstring(pref_string)?.select_pronoun(self, name)
}
/// Parse a pref_string.

View file

@ -130,7 +130,7 @@ impl Preference for UserPreferences {
let version = version_byte >> 3;
let varient = version_byte & 0b111;
match (version, varient) {
(0, 0) => UserPreferencesV0::from_prefstring_bytes(bytes).map(|prefs| UserPreferences::V0(prefs)),
(0, 0) => UserPreferencesV0::from_prefstring_bytes(bytes).map(UserPreferences::V0),
_ => Err(ParseError::VersionMismatch {
expected_version: 0..1,
expected_variant: 0..1,

View file

@ -94,7 +94,7 @@ impl Preference for UserPreferencesV0 {
fn from_prefstring_bytes(pbytes: &[u8]) -> Result<Self, ParseError> {
// Some simple error checks
if pbytes.len() == 0 {
if pbytes.is_empty() {
return Err(ParseError::ZeroLengthPrefstring);
} else if pbytes[0] != 00 {
return Err(ParseError::VersionMismatch {
@ -152,6 +152,7 @@ impl Preference for UserPreferencesV0 {
.unwrap();
let default_enabled = num_zeros < prefs.len() / 2;
let mut commands = Vec::new();
#[allow(clippy::branches_sharing_code)]
if default_enabled {
let mut last_default = -1;
for (i, w) in prefs.iter().enumerate() {
@ -305,7 +306,7 @@ mod tests {
fn check_table(actual: WeightedTable<&Pronoun>, expected: Vec<(&str, u8)>) {
let actual_simplified = actual.weights()
.into_iter()
.iter()
.filter(|(_, weight)| **weight > 0)
.map(|(pronoun, weight)| (pronoun.subject_pronoun.as_str(), *weight))
.collect::<HashMap<&str, u8>>();

View file

@ -103,8 +103,7 @@ impl<Loot: Eq + Ord + Hash + Copy + Debug> WeightedTable<Loot> {
let random = pcg64(generator) % sum_weights;
rollable_table.iter()
.filter(|(weight, _)| random < *weight)
.next()
.find(|(weight, _)| random < *weight)
.expect("A table was generated with zero entries. This should be impossible.")
.1
}