Skip to content

Commit

Permalink
docs: add use case description to Storage API host functions along wi…
Browse files Browse the repository at this point in the history
…th reference to implementation repo example
  • Loading branch information
denbite committed Nov 21, 2024
1 parent 3156836 commit 3985806
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions near-sdk/src/environment/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,10 @@ pub fn log(message: &[u8]) {
/// Writes key-value into storage.
/// If another key-value existed in the storage with the same key it returns `true`, otherwise `false`.
///
/// # Use cases
/// Storage functions are typically used to upgrade/migrate a contract state, preventing errors like `Cannot deserialize the contract state` after rolling out the breaking changes to the network.
/// For practical examples, see different implementations in [this repository](https://github.com/near-examples/update-migrate-rust).
///
/// # Examples
/// ```
/// use near_sdk::env::{storage_write, storage_read};
Expand All @@ -1696,6 +1700,10 @@ pub fn storage_write(key: &[u8], value: &[u8]) -> bool {
}
/// Reads the value stored under the given key.
///
/// # Use cases
/// Storage functions are typically used to upgrade/migrate a contract state, preventing errors like `Cannot deserialize the contract state` after rolling out the breaking changes to the network.
/// For practical examples, see different implementations in [this repository](https://github.com/near-examples/update-migrate-rust).
///
/// # Examples
/// ```
/// use near_sdk::env::{storage_write, storage_read};
Expand All @@ -1714,6 +1722,10 @@ pub fn storage_read(key: &[u8]) -> Option<Vec<u8>> {
/// Removes the value stored under the given key.
/// If key-value existed returns `true`, otherwise `false`.
///
/// # Use cases
/// Storage functions are typically used to upgrade/migrate a contract state, preventing errors like `Cannot deserialize the contract state` after rolling out the breaking changes to the network.
/// For practical examples, see different implementations in [this repository](https://github.com/near-examples/update-migrate-rust).
///
/// # Examples
/// ```
/// use near_sdk::env::{storage_write, storage_remove};
Expand All @@ -1731,6 +1743,10 @@ pub fn storage_remove(key: &[u8]) -> bool {
}
/// Reads the most recent value that was evicted with `storage_write` or `storage_remove` command.
///
/// # Use cases
/// Storage functions are typically used to upgrade/migrate a contract state, preventing errors like `Cannot deserialize the contract state` after rolling out the breaking changes to the network.
/// For practical examples, see different implementations in [this repository](https://github.com/near-examples/update-migrate-rust).
///
/// # Examples
/// ```
/// use near_sdk::env::{storage_write, storage_remove, storage_get_evicted};
Expand All @@ -1742,6 +1758,10 @@ pub fn storage_get_evicted() -> Option<Vec<u8>> {
}
/// Checks if there is a key-value in the storage.
///
/// # Use cases
/// Storage functions are typically used to upgrade/migrate a contract state, preventing errors like `Cannot deserialize the contract state` after rolling out the breaking changes to the network.
/// For practical examples, see different implementations in [this repository](https://github.com/near-examples/update-migrate-rust).
///
/// # Examples
/// ```
/// use near_sdk::env::{storage_write, storage_has_key};
Expand Down

0 comments on commit 3985806

Please sign in to comment.