increment

Function increment 

Source
pub fn increment(key: &str, delta: i64) -> Result<i64>
Expand description

Atomically increment a numeric value

If the key doesn’t exist, creates it with delta as the initial value. Uses compare-and-swap internally with automatic retries.

§Arguments

  • key - The key to increment
  • delta - The amount to add (can be negative)

§Returns

  • Ok(new_value) - The new value after increment
  • Err(StorageError) - Storage operation failed or value is not a valid i64

§Example

// Increment a counter
let new_count = storage::increment("page_views", 1)?;
println!("Page views: {}", new_count);

// Decrement (using negative delta)
let remaining = storage::increment("credits", -10)?;
println!("Remaining credits: {}", remaining);