Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Improve MemoryTemporaryStorage documentation #711

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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