From a8e05c660059a19994b46a2949d1c79ca4b4d579 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Mon, 26 Aug 2024 18:49:17 +0200 Subject: fix clippy suggestions --- src/agent.rs | 2 +- src/event.rs | 6 +++++- src/lib.rs | 2 +- src/raw/types.rs | 60 ++++++++++++++------------------------------------------ 4 files changed, 22 insertions(+), 48 deletions(-) diff --git a/src/agent.rs b/src/agent.rs index 4076df2..dae9f56 100644 --- a/src/agent.rs +++ b/src/agent.rs @@ -618,7 +618,7 @@ impl TryFrom<&raw::Agent> for Agent { condition: raw_agent.condition, instance_id: 0, first_aware: 0, - last_aware: u64::max_value(), + last_aware: u64::MAX, master_agent: None, phantom_data: PhantomData, }) diff --git a/src/event.rs b/src/event.rs index b6caa5d..609992b 100644 --- a/src/event.rs +++ b/src/event.rs @@ -4,6 +4,7 @@ use super::raw; use std::convert::TryFrom; +use std::fmt::Write; use std::io; use byteorder::{BigEndian, WriteBytesExt, LE}; @@ -549,7 +550,10 @@ fn get_api_guild_string(bytes: &[u8; 16]) -> Option { ]; let result = PACKS .iter() - .map(|p| p.iter().map(|i| format!("{:02X}", bytes[*i])).collect()) + .map(|p| p.iter().fold(String::new(), |mut output, i| { + let _ = write!(output, "{:02X}", bytes[*i]); + output + })) .collect::>() .join("-"); Some(result) diff --git a/src/lib.rs b/src/lib.rs index 3677871..488cd45 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -82,7 +82,7 @@ //! reasons: //! //! * The only sensible source for logs is the arcdps addon itself, most applications only consume -//! them. +//! them. //! * The library was needed for reading support, and writing support has never been a priority. //! //! While there are legitimate use cases for writing/modification support, they are currently not diff --git a/src/raw/types.rs b/src/raw/types.rs index ce22f5f..1bc3d08 100644 --- a/src/raw/types.rs +++ b/src/raw/types.rs @@ -7,7 +7,7 @@ use std::hash::Hash; /// The "friend or foe" enum. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, FromPrimitive)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash, FromPrimitive)] pub enum IFF { /// Green vs green, red vs red. Friend, @@ -16,18 +16,13 @@ pub enum IFF { /// Something very wrong happened. Unknown, /// Field is not used in this kind of event. + #[default] None, } -impl Default for IFF { - fn default() -> Self { - IFF::None - } -} - /// Combat result (physical) #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, FromPrimitive)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash, FromPrimitive)] pub enum CbtResult { /// Good physical hit Normal, @@ -52,20 +47,16 @@ pub enum CbtResult { /// Hit was breakbar damage. Breakbar, /// Field is not used in this kind of event. + #[default] None, } -impl Default for CbtResult { - fn default() -> Self { - CbtResult::None - } -} - /// Combat activation #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, FromPrimitive)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash, FromPrimitive)] pub enum CbtActivation { /// Field is not used in this kind of event. + #[default] None, /// Activation without quickness Normal, @@ -79,20 +70,15 @@ pub enum CbtActivation { Reset, } -impl Default for CbtActivation { - fn default() -> Self { - CbtActivation::None - } -} - /// Combat state change /// /// The referenced fields are of the [`CbtEvent`](struct.CbtEvent.html) /// struct. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, FromPrimitive)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash, FromPrimitive)] pub enum CbtStateChange { /// Field is not used in this kind of event. + #[default] None, /// `src_agent` entered combat. /// @@ -213,17 +199,12 @@ pub enum CbtStateChange { BarrierUpdate, } -impl Default for CbtStateChange { - fn default() -> Self { - CbtStateChange::None - } -} - /// Combat buff remove type #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, FromPrimitive)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash, FromPrimitive)] pub enum CbtBuffRemove { /// Field is not used in this kind of event. + #[default] None, /// All stacks removed. All, @@ -237,12 +218,6 @@ pub enum CbtBuffRemove { Manual, } -impl Default for CbtBuffRemove { - fn default() -> Self { - CbtBuffRemove::None - } -} - /// Custom skill ids #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, FromPrimitive)] @@ -257,9 +232,10 @@ pub enum CbtCustomSkill { /// Language #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, FromPrimitive)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash, FromPrimitive)] pub enum Language { /// English. + #[default] Eng = 0, /// French. Fre = 2, @@ -269,12 +245,6 @@ pub enum Language { Spa = 4, } -impl Default for Language { - fn default() -> Self { - Language::Eng - } -} - /// Buff formula attributes. /// /// Variants prefixed with `Custom` are not native to the game client but rather variants added by @@ -402,7 +372,7 @@ impl Agent { /// Gadgets are entities spawned by some skills, like the "Binding Roots" /// spawned by Entangle. pub fn is_gadget(&self) -> bool { - self.is_elite == std::u32::MAX && (self.prof & 0xffff_0000) == 0xffff_0000 + self.is_elite == u32::MAX && (self.prof & 0xffff_0000) == 0xffff_0000 } /// Checks whether this agent is a character. @@ -410,12 +380,12 @@ impl Agent { /// Characters are entities like clones, pets, minions, spirits, but also /// minis. pub fn is_character(&self) -> bool { - self.is_elite == std::u32::MAX && (self.prof & 0xffff_0000) != 0xffff_0000 + self.is_elite == u32::MAX && (self.prof & 0xffff_0000) != 0xffff_0000 } /// Checks whether this agent is a player. pub fn is_player(&self) -> bool { - self.is_elite != std::u32::MAX + self.is_elite != u32::MAX } } -- cgit v1.2.3