Skip to content

Commit

Permalink
docs: Improve MemoryTemporaryStorage documentation
Browse files Browse the repository at this point in the history
- Add comprehensive documentation for MemoryTemporaryStorage struct explaining its purpose and behavior
- Document remove() method with clear description of its return value
- Document take() method with explanation of its functionality and return behavior
- Fix missing documentation for core storage operations
  • Loading branch information
GarmashAlex authored Jan 11, 2025
1 parent 9319c61 commit 59d0e54
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions base/src/mem_tmp_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ pub type StorageMap = BTreeMap<Vec<u8>, Vec<u8>>;
////// Runtime Code
//////

/// TODO docs
/// A temporary in-memory key-value storage implementation that provides basic storage operations.
/// This storage is cleared at the beginning of each block building and is not fork-aware.
/// It can be used for storing auxiliary information that doesn't need to persist across blocks.
pub struct MemoryTemporaryStorage;
impl MemoryTemporaryStorage {
/// Returns the value under `key` from the memory temporal storage.
Expand All @@ -24,12 +26,14 @@ impl MemoryTemporaryStorage {
.and_then(|raw| T::decode(&mut raw.as_slice()).ok())
}

/// TODO docs
/// Removes a value from the memory temporal storage by its key.
/// Returns true if the value was present and removed, false otherwise.
pub fn remove(key: &[u8]) -> bool {
hosted_mem_tmp_storage::take(key).is_some()
}

/// TODO docs
/// Removes and returns the value associated with the given key from the memory temporal storage.
/// Returns None if the key doesn't exist.
pub fn take<T: Decode>(key: &[u8]) -> Option<T> {
hosted_mem_tmp_storage::take(key).and_then(|raw| T::decode(&mut raw.as_slice()).ok())
}
Expand Down

0 comments on commit 59d0e54

Please sign in to comment.