decrement

Function decrement 

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

Atomically decrement a numeric value

If the key doesn’t exist, creates it with -delta as the initial value. This is equivalent to increment(key, -delta).

§Arguments

  • key - The key to decrement
  • delta - The amount to subtract

§Returns

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

§Example

// Decrement inventory
let remaining = storage::decrement("stock:item123", 1)?;
if remaining < 0 {
    println!("Out of stock!");
}