extract amount method for fungible/s Imbalance (#1847)

Introduces an `extract` amount method for `fungible/s` `Imbalance`.
This commit is contained in:
Muharem
2023-10-16 17:16:59 +02:00
committed by GitHub
parent 646ecd0edb
commit c422e3f577
4 changed files with 33 additions and 0 deletions
@@ -100,6 +100,11 @@ mod imbalances {
mem::forget(self);
(Self(first), Self(second))
}
fn extract(&mut self, amount: T::Balance) -> Self {
let new = self.0.min(amount);
self.0 = self.0 - new;
Self(new)
}
fn merge(mut self, other: Self) -> Self {
self.0 = self.0.saturating_add(other.0);
mem::forget(other);
@@ -159,6 +164,11 @@ mod imbalances {
mem::forget(self);
(Self(first), Self(second))
}
fn extract(&mut self, amount: T::Balance) -> Self {
let new = self.0.min(amount);
self.0 = self.0 - new;
Self(new)
}
fn merge(mut self, other: Self) -> Self {
self.0 = self.0.saturating_add(other.0);
mem::forget(other);