From 7f5a25240f75ef36c9a374011391cb8cb572f5b8 Mon Sep 17 00:00:00 2001 From: vad Date: Wed, 20 May 2026 14:46:39 +0200 Subject: [PATCH] feat: Add methods for checked arithmetics to `StakeHistoryEntry` The usage of existing `std::ops::Add` implementation triggers the `arithmetic_side_effects` clippy lint. To allow addressing it, add the following methods to `StakeHistoryEntry`: * `checked_add` * `wrapping_add` * `saturating_add` --- interface/src/stake_history.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/interface/src/stake_history.rs b/interface/src/stake_history.rs index c65e7fa1..c1497d91 100644 --- a/interface/src/stake_history.rs +++ b/interface/src/stake_history.rs @@ -43,6 +43,30 @@ impl StakeHistoryEntry { ..Self::default() } } + + pub fn checked_add(self, rhs: StakeHistoryEntry) -> Option { + Some(Self { + effective: self.effective.checked_add(rhs.effective)?, + activating: self.activating.checked_add(rhs.activating)?, + deactivating: self.deactivating.checked_add(rhs.deactivating)?, + }) + } + + pub fn wrapping_add(self, rhs: StakeHistoryEntry) -> Self { + Self { + effective: self.effective.wrapping_add(rhs.effective), + activating: self.activating.wrapping_add(rhs.activating), + deactivating: self.deactivating.wrapping_add(rhs.deactivating), + } + } + + pub fn saturating_add(self, rhs: StakeHistoryEntry) -> Self { + Self { + effective: self.effective.saturating_add(rhs.effective), + activating: self.activating.saturating_add(rhs.activating), + deactivating: self.deactivating.saturating_add(rhs.deactivating), + } + } } impl std::ops::Add for StakeHistoryEntry {