From 49ff33371240b0d6fdd1f15cf76380e52d3a1b78 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh <37006439+qalisander@users.noreply.github.com> Date: Tue, 10 Dec 2024 20:56:15 +0400 Subject: [PATCH] ref: drop math for storage guard (#446) Drop `add_assign_unchecked` and `sub_assign_unchecked` functions for `StorageGuardMut`, since guard already implements `Deref` and `DerefMut` to wrapped types. --- contracts/src/utils/math/storage.rs | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/contracts/src/utils/math/storage.rs b/contracts/src/utils/math/storage.rs index fb1e295ef..a0a762e0b 100644 --- a/contracts/src/utils/math/storage.rs +++ b/contracts/src/utils/math/storage.rs @@ -1,20 +1,13 @@ //! Simple math operations missing in `stylus_sdk::storage`. use alloy_primitives::Uint; -use stylus_sdk::storage::{StorageGuardMut, StorageUint}; +use stylus_sdk::storage::StorageUint; +/// Adds value and assign the result to `self`, ignoring overflow. pub(crate) trait AddAssignUnchecked { + /// Adds `rhs` and assign the result to `self`, ignoring overflow. fn add_assign_unchecked(&mut self, rhs: T); } -impl AddAssignUnchecked> - for StorageGuardMut<'_, StorageUint> -{ - fn add_assign_unchecked(&mut self, rhs: Uint) { - let new_balance = self.get() + rhs; - self.set(new_balance); - } -} - impl AddAssignUnchecked> for StorageUint { @@ -24,19 +17,12 @@ impl AddAssignUnchecked> } } +/// Subtract value and assign the result to `self`, ignoring overflow. pub(crate) trait SubAssignUnchecked { + /// Subtract `rhs` and assign the result to `self`, ignoring overflow. fn sub_assign_unchecked(&mut self, rhs: T); } -impl SubAssignUnchecked> - for StorageGuardMut<'_, StorageUint> -{ - fn sub_assign_unchecked(&mut self, rhs: Uint) { - let new_balance = self.get() - rhs; - self.set(new_balance); - } -} - impl SubAssignUnchecked> for StorageUint {