Struct gear_core::gas::GasAllowanceCounter
source · pub struct GasAllowanceCounter(_);Expand description
Gas allowance counter with some predefined maximum value.
Implementations§
source§impl GasAllowanceCounter
impl GasAllowanceCounter
sourcepub fn new(initial_amount: u64) -> Self
pub fn new(initial_amount: u64) -> Self
New limited gas allowance counter with initial value to spend.
sourcepub fn charge<T: Into<u64>>(&mut self, amount: T) -> ChargeResult
pub fn charge<T: Into<u64>>(&mut self, amount: T) -> ChargeResult
Account for used gas allowance.
If there is no enough gas, then makes saturating charge and returns NotEnough.
Else charges gas and returns Enough.
sourcepub fn charge_if_enough<T: Into<u64>>(&mut self, amount: T) -> ChargeResult
pub fn charge_if_enough<T: Into<u64>>(&mut self, amount: T) -> ChargeResult
Account for used gas allowance.
If there is no enough gas, then does nothing and returns ChargeResult::NotEnough.
Else charges gas and returns ChargeResult::Enough.
Trait Implementations§
source§impl Clone for GasAllowanceCounter
impl Clone for GasAllowanceCounter
source§fn clone(&self) -> GasAllowanceCounter
fn clone(&self) -> GasAllowanceCounter
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl RefUnwindSafe for GasAllowanceCounter
impl Send for GasAllowanceCounter
impl Sync for GasAllowanceCounter
impl Unpin for GasAllowanceCounter
impl UnwindSafe for GasAllowanceCounter
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more