pub struct Accumulator { /* private fields */ }Expand description
A 128-bit unsigned integer accumulator.
Implementations§
Source§impl Accumulator
impl Accumulator
Sourcepub fn get<'a>(&self, ctx: &Context<'_>) -> Result<u128, ClientError<u8>>
pub fn get<'a>(&self, ctx: &Context<'_>) -> Result<u128, ClientError<u8>>
Gets the current value, defaulting always to 0.
Sourcepub fn add<'a>(
&self,
ctx: &mut Context<'_>,
value: u128,
) -> Result<u128, ClientError<u8>>
pub fn add<'a>( &self, ctx: &mut Context<'_>, value: u128, ) -> Result<u128, ClientError<u8>>
Adds the given value to the current value.
Sourcepub fn safe_sub<'a>(
&self,
ctx: &mut Context<'_>,
value: u128,
) -> Result<u128, ClientError<SafeSubError>>
pub fn safe_sub<'a>( &self, ctx: &mut Context<'_>, value: u128, ) -> Result<u128, ClientError<SafeSubError>>
Subtracts the given value from the current value, returning an error if the subtraction would result in a negative value.
Trait Implementations§
Source§impl StateObjectResource for Accumulator
impl StateObjectResource for Accumulator
Source§unsafe fn new(
scope: &[u8],
prefix: u8,
) -> Result<Accumulator, InitializationError>
unsafe fn new( scope: &[u8], prefix: u8, ) -> Result<Accumulator, InitializationError>
Creates a new resource.
This should only be called in generated code.
Do not call this function directly.
Auto Trait Implementations§
impl Freeze for Accumulator
impl RefUnwindSafe for Accumulator
impl Send for Accumulator
impl Sync for Accumulator
impl Unpin for Accumulator
impl UnwindSafe for Accumulator
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