pub struct Lazy<T>where
T: BorshSerialize,{ /* private fields */ }
Expand description
An persistent lazily loaded value, that stores a value in the storage.
This will only write to the underlying store if the value has changed, and will only read the existing value from storage once.
§Examples
use near_sdk::store::Lazy;
let mut a = Lazy::new(b"a", "test string".to_string());
assert_eq!(*a, "test string");
*a = "new string".to_string();
assert_eq!(a.get(), "new string");
Implementations§
source§impl<T> Lazy<T>where
T: BorshSerialize,
impl<T> Lazy<T>where
T: BorshSerialize,
sourcepub fn new<S>(key: S, value: T) -> Selfwhere
S: IntoStorageKey,
pub fn new<S>(key: S, value: T) -> Selfwhere
S: IntoStorageKey,
Initializes new lazily loaded value with a given storage prefix and the value to initialize it with.
This prefix can be anything that implements IntoStorageKey
. The prefix is used when
storing and looking up values in storage to ensure no collisions with other collections.
source§impl<T> Lazy<T>where
T: BorshSerialize + BorshDeserialize,
impl<T> Lazy<T>where
T: BorshSerialize + BorshDeserialize,
Trait Implementations§
source§impl<T> AsMut<T> for Lazy<T>where
T: BorshSerialize + BorshDeserialize,
impl<T> AsMut<T> for Lazy<T>where
T: BorshSerialize + BorshDeserialize,
source§impl<T> AsRef<T> for Lazy<T>where
T: BorshSerialize + BorshDeserialize,
impl<T> AsRef<T> for Lazy<T>where
T: BorshSerialize + BorshDeserialize,
source§impl<T> BorshDeserialize for Lazy<T>where
T: BorshSerialize,
impl<T> BorshDeserialize for Lazy<T>where
T: BorshSerialize,
fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self, Error>
source§fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
Deserializes this instance from a given slice of bytes.
Updates the buffer to point at the remaining bytes.
source§fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
Deserialize this instance from a slice of bytes.
fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>where
R: Read,
source§impl<T> BorshSerialize for Lazy<T>where
T: BorshSerialize,
impl<T> BorshSerialize for Lazy<T>where
T: BorshSerialize,
source§impl<T> Deref for Lazy<T>where
T: BorshSerialize + BorshDeserialize,
impl<T> Deref for Lazy<T>where
T: BorshSerialize + BorshDeserialize,
source§impl<T> DerefMut for Lazy<T>where
T: BorshSerialize + BorshDeserialize,
impl<T> DerefMut for Lazy<T>where
T: BorshSerialize + BorshDeserialize,
source§impl<T> Drop for Lazy<T>where
T: BorshSerialize,
impl<T> Drop for Lazy<T>where
T: BorshSerialize,
source§impl<T> Ord for Lazy<T>
impl<T> Ord for Lazy<T>
source§impl<T> PartialEq for Lazy<T>
impl<T> PartialEq for Lazy<T>
source§impl<T> PartialOrd for Lazy<T>
impl<T> PartialOrd for Lazy<T>
source§fn le(&self, other: &Self) -> bool
fn le(&self, other: &Self) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl<T> Eq for Lazy<T>
Auto Trait Implementations§
impl<T> !Freeze for Lazy<T>
impl<T> RefUnwindSafe for Lazy<T>where
T: UnwindSafe + RefUnwindSafe,
impl<T> Send for Lazy<T>where
T: Send,
impl<T> !Sync for Lazy<T>
impl<T> Unpin for Lazy<T>where
T: Unpin,
impl<T> UnwindSafe for Lazy<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more