Skip to content

Commit

Permalink
feat: Introduced 'remove' method for 'near_sdk::store::Lazy' collecti…
Browse files Browse the repository at this point in the history
…on (#1238)
  • Loading branch information
ruseinov committed Aug 12, 2024
1 parent f3606e6 commit 3acc8a6
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions near-sdk/src/store/lazy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ where
}
}
}

/// Removes the underlying storage item. Useful for deprecating the obsolete [`Lazy`] values.
pub fn remove(&mut self) -> bool {
env::storage_remove(&self.storage_key)
}
}

impl<T> Lazy<T>
Expand Down Expand Up @@ -185,6 +190,15 @@ mod tests {
assert_eq!(lazy_loaded, b);
}

#[test]
pub fn test_remove() {
let mut lazy = Lazy::new(b"m", 8u8);
lazy.flush();
assert!(env::storage_has_key(b"m"));
lazy.remove();
assert!(!env::storage_has_key(b"m"));
}

#[test]
pub fn test_debug() {
let mut lazy = Lazy::new(b"m", 8u8);
Expand Down

0 comments on commit 3acc8a6

Please sign in to comment.