Fix clippy lints

This commit is contained in:
Benoît du Garreau 2020-12-13 15:57:10 +01:00 committed by Marcel Märtens
parent 850eb1c293
commit ce9d706ed4
5 changed files with 14 additions and 10 deletions

View File

@ -92,7 +92,7 @@ impl<T: Compound> AssetExt for T {
pub struct Image(pub Arc<DynamicImage>);
impl Image {
pub fn to_image(&self) -> Arc<DynamicImage> { self.0.clone() }
pub fn to_image(&self) -> Arc<DynamicImage> { Arc::clone(&self.0) }
}
pub struct ImageLoader;

View File

@ -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)
}
}

View File

@ -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()),

View File

@ -67,6 +67,7 @@ impl RecipeBook {
#[derive(Deserialize)]
#[serde(transparent)]
#[allow(clippy::type_complexity)]
struct RawRecipeBook(HashMap<String, ((String, u32), Vec<(String, u32)>)>);
impl assets::Asset for RawRecipeBook {

View File

@ -152,7 +152,7 @@ impl assets::Loader<Localization> 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 =