Clippy fixes and documentation
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-06-24 15:05:58 +02:00
parent 78bb91093b
commit 3400d9ec1e
12 changed files with 61 additions and 4 deletions

View File

@@ -5,6 +5,7 @@ use anyhow_ext::{ensure, Result};
use indexmap::IndexMap;
use parking_lot::RwLock;
use std::fmt::Debug;
use std::ops::Deref;
use std::sync::Arc;
/// A library of all natures that can be used, stored by their names.
@@ -64,7 +65,7 @@ impl NatureLibrary for NatureLibraryImpl {
for kv in read_lock.iter() {
// As natures can't be copied, and should always be the same reference as the value
// in the map, we just compare by reference.
if Arc::ptr_eq(&kv.1, nature) {
if kv.1.eq(nature.deref()) {
return Ok(kv.0.clone());
}
}

View File

@@ -77,6 +77,9 @@ impl TypeLibraryImpl {
}
impl TypeLibraryImpl {
/// Helper function to get the effectiveness for a single attacking type against a single
/// defending type, without having to acquire read locks multiple times when used in a loop.
#[inline]
fn get_single_effectiveness_with_lock(
lock: &RwLockReadGuard<Vec<Vec<f32>>>,
attacking: TypeIdentifier,

View File

@@ -20,6 +20,9 @@ pub trait Nature: Debug {
/// Calculates the modifier for a given stat. If it's the increased stat, returns the increased
/// modifier, if it's the decreased stat, returns the decreased modifier. Otherwise returns 1.0
fn get_stat_modifier(&self, stat: Statistic) -> f32;
/// Checks if two natures are equal.
fn eq(&self, other: &dyn Nature) -> bool;
}
/// A nature is an attribute on a Pokemon that modifies the effective base stats on a Pokemon. They
@@ -83,6 +86,10 @@ impl Nature for NatureImpl {
1.0
}
}
fn eq(&self, other: &dyn Nature) -> bool {
std::ptr::eq(self, other as *const dyn Nature as *const Self)
}
}
#[cfg(test)]
@@ -100,6 +107,7 @@ pub(crate) mod tests {
fn increased_modifier(&self) -> f32;
fn decreased_modifier(&self) -> f32;
fn get_stat_modifier(&self, stat: Statistic) -> f32;
fn eq(&self, other: &dyn Nature) -> bool;
}
}
}

View File

@@ -56,6 +56,9 @@ pub trait Form: Debug {
/// Arbitrary flags that can be applied to the move.
fn has_flag_by_hash(&self, key_hash: u32) -> bool;
/// Check if two forms are equal.
fn eq(&self, other: &dyn Form) -> bool;
}
/// A form is a variant of a specific species. A species always has at least one form, but can have
@@ -217,6 +220,10 @@ impl Form for FormImpl {
fn has_flag_by_hash(&self, key_hash: u32) -> bool {
self.flags.contains::<u32>(&key_hash)
}
fn eq(&self, other: &dyn Form) -> bool {
std::ptr::eq(self, other as *const dyn Form as *const Self)
}
}
#[cfg(test)]
@@ -247,6 +254,7 @@ pub(crate) mod tests {
fn get_random_hidden_ability<'a>(&'a self, rand: &mut Random) -> Result<&'a StringKey>;
fn has_flag(&self, key: &StringKey) -> bool;
fn has_flag_by_hash(&self, key_hash: u32) -> bool;
fn eq(&self, other: &dyn Form) -> bool;
}
}
}