Skip to content

Commit

Permalink
frame-support: RuntimeDebug\Eq\PartialEq impls for Imbalance (#1717)
Browse files Browse the repository at this point in the history
Derive `RuntimeDebug\Eq\PartialEq` but do not bound any generics.

This achieved by using their equivalent no bound versions:
`EqNoBound\PartialEqNoBound\RuntimeDebugNoBound`.

Deriving with `Debug`, `Eq`, and `PartialEq` for the `Debt` and `Credit`
type aliases of `Imbalance` is not feasible due to the `OnDrop` and
`OppositeOnDrop` generic types lacking implementations of the same
traits.

This absence posed challenges in testing and any scenarios that demanded
the traits implementations for the type.
  • Loading branch information
muharem committed Sep 29, 2023
1 parent 9485b0b commit 7d4f829
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ use crate::traits::{
misc::{SameOrOther, TryDrop},
tokens::Balance,
};
use sp_runtime::{traits::Zero, RuntimeDebug};
use frame_support_procedural::{EqNoBound, PartialEqNoBound, RuntimeDebugNoBound};
use sp_runtime::traits::Zero;
use sp_std::marker::PhantomData;

/// Handler for when an imbalance gets dropped. This could handle either a credit (negative) or
Expand All @@ -43,7 +44,7 @@ impl<Balance> HandleImbalanceDrop<Balance> for () {
///
/// Importantly, it has a special `Drop` impl, and cannot be created outside of this module.
#[must_use]
#[derive(RuntimeDebug, Eq, PartialEq)]
#[derive(EqNoBound, PartialEqNoBound, RuntimeDebugNoBound)]
pub struct Imbalance<
B: Balance,
OnDrop: HandleImbalanceDrop<B>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ use crate::traits::{
misc::{SameOrOther, TryDrop},
tokens::{AssetId, Balance},
};
use sp_runtime::{traits::Zero, RuntimeDebug};
use frame_support_procedural::{EqNoBound, PartialEqNoBound, RuntimeDebugNoBound};
use sp_runtime::traits::Zero;
use sp_std::marker::PhantomData;

/// Handler for when an imbalance gets dropped. This could handle either a credit (negative) or
Expand All @@ -38,7 +39,7 @@ pub trait HandleImbalanceDrop<AssetId, Balance> {
///
/// Importantly, it has a special `Drop` impl, and cannot be created outside of this module.
#[must_use]
#[derive(RuntimeDebug, Eq, PartialEq)]
#[derive(EqNoBound, PartialEqNoBound, RuntimeDebugNoBound)]
pub struct Imbalance<
A: AssetId,
B: Balance,
Expand Down

0 comments on commit 7d4f829

Please sign in to comment.