From ce9d706ed4997bc30341c7c547d4dbf11672e537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20du=20Garreau?= Date: Sun, 13 Dec 2020 15:57:10 +0100 Subject: [PATCH] Fix clippy lints --- common/src/assets.rs | 2 +- common/src/comp/inventory/item/mod.rs | 17 ++++++++++------- common/src/comp/inventory/item/tool.rs | 2 +- common/src/recipe.rs | 1 + voxygen/src/i18n.rs | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/common/src/assets.rs b/common/src/assets.rs index a10339d3a0..9ec243d2d8 100644 --- a/common/src/assets.rs +++ b/common/src/assets.rs @@ -92,7 +92,7 @@ impl AssetExt for T { pub struct Image(pub Arc); impl Image { - pub fn to_image(&self) -> Arc { self.0.clone() } + pub fn to_image(&self) -> Arc { Arc::clone(&self.0) } } pub struct ImageLoader; diff --git a/common/src/comp/inventory/item/mod.rs b/common/src/comp/inventory/item/mod.rs index 749d4593cf..6dc1fdc87b 100644 --- a/common/src/comp/inventory/item/mod.rs +++ b/common/src/comp/inventory/item/mod.rs @@ -198,6 +198,9 @@ impl assets::Asset for RawItemDef { const EXTENSION: &'static str = "ron"; } +#[derive(Debug)] +pub struct OperationFailure; + impl Item { // TODO: consider alternatives such as default abilities that can be added to a // loadout when no weapon is present @@ -275,30 +278,30 @@ impl Item { /// up by another player. pub fn put_in_world(&mut self) { self.reset_item_id() } - pub fn increase_amount(&mut self, increase_by: u32) -> Result<(), ()> { + pub fn increase_amount(&mut self, increase_by: u32) -> Result<(), OperationFailure> { let amount = u32::from(self.amount); self.amount = amount .checked_add(increase_by) .and_then(NonZeroU32::new) - .ok_or(())?; + .ok_or(OperationFailure)?; Ok(()) } - pub fn decrease_amount(&mut self, decrease_by: u32) -> Result<(), ()> { + pub fn decrease_amount(&mut self, decrease_by: u32) -> Result<(), OperationFailure> { let amount = u32::from(self.amount); self.amount = amount .checked_sub(decrease_by) .and_then(NonZeroU32::new) - .ok_or(())?; + .ok_or(OperationFailure)?; Ok(()) } - pub fn set_amount(&mut self, give_amount: u32) -> Result<(), ()> { + pub fn set_amount(&mut self, give_amount: u32) -> Result<(), OperationFailure> { if give_amount == 1 || self.item_def.is_stackable() { - self.amount = NonZeroU32::new(give_amount).ok_or(())?; + self.amount = NonZeroU32::new(give_amount).ok_or(OperationFailure)?; Ok(()) } else { - Err(()) + Err(OperationFailure) } } diff --git a/common/src/comp/inventory/item/tool.rs b/common/src/comp/inventory/item/tool.rs index 3d489a09ee..c1843360d5 100644 --- a/common/src/comp/inventory/item/tool.rs +++ b/common/src/comp/inventory/item/tool.rs @@ -162,7 +162,7 @@ impl assets::Compound for AbilityMap { .iter() .map(|(kind, set)| { ( - kind.clone(), + *kind, // expect cannot fail because CharacterAbility always // provides a default value in case of failure set.map_ref(|s| cache.load_expect(&s).cloned()), diff --git a/common/src/recipe.rs b/common/src/recipe.rs index 7eb6d354ae..24ae29396f 100644 --- a/common/src/recipe.rs +++ b/common/src/recipe.rs @@ -67,6 +67,7 @@ impl RecipeBook { #[derive(Deserialize)] #[serde(transparent)] +#[allow(clippy::type_complexity)] struct RawRecipeBook(HashMap)>); impl assets::Asset for RawRecipeBook { diff --git a/voxygen/src/i18n.rs b/voxygen/src/i18n.rs index 8cb16b4e2d..409032d7b2 100644 --- a/voxygen/src/i18n.rs +++ b/voxygen/src/i18n.rs @@ -152,7 +152,7 @@ impl assets::Loader for LocalizationLoader { } for value in asked_localization.vector_map.values_mut() { - *value = value.into_iter().map(|s| deunicode(s)).collect(); + *value = value.iter().map(|s| deunicode(s)).collect(); } } asked_localization.metadata.language_name =