diff --git a/Cargo.toml b/Cargo.toml index 54fa16d..2770fbe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ license = "MIT" [dependencies] alloy-primitives = "0.8" bigdecimal = "0.4.5" +derive_more = { version = "1.0.0", features = ["deref"] } eth_checksum = { version = "0.1.2", optional = true } lazy_static = "1.5" num-bigint = "0.4" diff --git a/src/entities/currency.rs b/src/entities/currency.rs index 51d3605..76059e1 100644 --- a/src/entities/currency.rs +++ b/src/entities/currency.rs @@ -1,5 +1,6 @@ use crate::prelude::*; use alloy_primitives::ChainId; +use derive_more::Deref; #[derive(Clone, Debug, Hash, PartialEq, Eq)] pub enum Currency { @@ -9,7 +10,7 @@ pub enum Currency { /// [`CurrencyLike`] is a generic struct representing a currency with a specific chain ID, /// decimals, symbol, name, and additional metadata. -#[derive(Clone, Debug, Hash, PartialEq, Eq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq, Deref)] pub struct CurrencyLike { /// The chain ID on which this currency resides pub chain_id: ChainId, @@ -24,19 +25,10 @@ pub struct CurrencyLike { pub name: Option, /// Metadata associated with the currency + #[deref] pub meta: M, } -/// Implement [`Deref`] to allow direct access to the metadata of the currency -impl Deref for CurrencyLike { - type Target = M; - - #[inline] - fn deref(&self) -> &Self::Target { - &self.meta - } -} - macro_rules! match_currency_method { ($method:ident, $return_type:ty) => { #[inline] diff --git a/src/entities/fractions/currency_amount.rs b/src/entities/fractions/currency_amount.rs index 3bcb606..3827b27 100644 --- a/src/entities/fractions/currency_amount.rs +++ b/src/entities/fractions/currency_amount.rs @@ -1,5 +1,5 @@ -/// External crate dependencies use crate::prelude::*; +use core::ops::Div; /// Currency amount struct that represents a rational amount of a currency pub type CurrencyAmount = FractionLike>; diff --git a/src/entities/fractions/fraction.rs b/src/entities/fractions/fraction.rs index 83460e8..ac73b03 100644 --- a/src/entities/fractions/fraction.rs +++ b/src/entities/fractions/fraction.rs @@ -1,15 +1,17 @@ use crate::prelude::*; use core::{ hash::{Hash, Hasher}, - ops::{Add, Deref, Mul, Sub}, + ops::{Add, Div, Mul, Sub}, }; +use derive_more::Deref; /// Struct representing a fraction with metadata -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Deref)] pub struct FractionLike { pub numerator: BigInt, pub denominator: BigInt, /// Metadata associated with the fraction + #[deref] pub meta: M, } @@ -24,16 +26,6 @@ impl Default for FractionLike { } } -/// Implement [`Deref`] to allow direct access to the metadata of the fraction -impl Deref for FractionLike { - type Target = M; - - #[inline] - fn deref(&self) -> &Self::Target { - &self.meta - } -} - /// Type alias for a simple Fraction without metadata pub type Fraction = FractionLike<()>; diff --git a/src/entities/fractions/price.rs b/src/entities/fractions/price.rs index 5207b72..ceea6ef 100644 --- a/src/entities/fractions/price.rs +++ b/src/entities/fractions/price.rs @@ -1,4 +1,3 @@ -/// External crate dependencies use crate::prelude::*; /// Type alias for a Price, a [`FractionLike`] with metadata [`PriceMeta`] diff --git a/src/prelude.rs b/src/prelude.rs index 489145d..540b856 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -25,12 +25,7 @@ pub use alloc::{ }; pub use alloy_primitives::{address, Address}; pub use bigdecimal::{BigDecimal, RoundingMode}; -pub use core::{ - cmp::Ordering, - num::NonZeroU64, - ops::{Deref, Div}, - str::FromStr, -}; +pub use core::{cmp::Ordering, num::NonZeroU64, str::FromStr}; pub use lazy_static::lazy_static; pub use num_bigint::{BigInt, BigUint, ToBigInt, ToBigUint}; pub use num_integer::Integer;