pub struct GasAllowanceCounter(/* private fields */);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 duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for GasAllowanceCounter
impl Debug for GasAllowanceCounter
Source§impl Decode for GasAllowanceCounter
impl Decode for GasAllowanceCounter
Source§fn decode<__CodecInputEdqy: Input>(
__codec_input_edqy: &mut __CodecInputEdqy,
) -> Result<Self, Error>
fn decode<__CodecInputEdqy: Input>( __codec_input_edqy: &mut __CodecInputEdqy, ) -> Result<Self, Error>
Attempt to deserialise the value from input.
Source§fn decode_into<I>(
input: &mut I,
dst: &mut MaybeUninit<Self>,
) -> Result<DecodeFinished, Error>where
I: Input,
fn decode_into<I>(
input: &mut I,
dst: &mut MaybeUninit<Self>,
) -> Result<DecodeFinished, Error>where
I: Input,
Attempt to deserialize the value from input into a pre-allocated piece of memory. Read more
Source§impl Encode for GasAllowanceCounter
impl Encode for GasAllowanceCounter
Source§fn size_hint(&self) -> usize
fn size_hint(&self) -> usize
If possible give a hint of expected size of the encoding. Read more
Source§fn encode_to<__CodecOutputEdqy: Output + ?Sized>(
&self,
__codec_dest_edqy: &mut __CodecOutputEdqy,
)
fn encode_to<__CodecOutputEdqy: Output + ?Sized>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy, )
Convert self to a slice and append it to the destination.
Source§fn using_encoded<__CodecOutputReturn, __CodecUsingEncodedCallback: FnOnce(&[u8]) -> __CodecOutputReturn>(
&self,
f: __CodecUsingEncodedCallback,
) -> __CodecOutputReturn
fn using_encoded<__CodecOutputReturn, __CodecUsingEncodedCallback: FnOnce(&[u8]) -> __CodecOutputReturn>( &self, f: __CodecUsingEncodedCallback, ) -> __CodecOutputReturn
Convert self to a slice and then invoke the given closure with it.
Source§fn encoded_size(&self) -> usize
fn encoded_size(&self) -> usize
Calculates the encoded size. Read more
impl EncodeLike for GasAllowanceCounter
Auto Trait Implementations§
impl Freeze for GasAllowanceCounter
impl RefUnwindSafe for GasAllowanceCounter
impl Send for GasAllowanceCounter
impl Sync for GasAllowanceCounter
impl Unpin for GasAllowanceCounter
impl UnsafeUnpin 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