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
sourceimpl<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.
sourceimpl<T> Lazy<T>where
T: BorshSerialize + BorshDeserialize,
impl<T> Lazy<T>where
T: BorshSerialize + BorshDeserialize,
Trait Implementations
sourceimpl<T> AsMut<T> for Lazy<T>where
T: BorshSerialize + BorshDeserialize,
impl<T> AsMut<T> for Lazy<T>where
T: BorshSerialize + BorshDeserialize,
sourceimpl<T> AsRef<T> for Lazy<T>where
T: BorshSerialize + BorshDeserialize,
impl<T> AsRef<T> for Lazy<T>where
T: BorshSerialize + BorshDeserialize,
sourceimpl<T> BorshDeserialize for Lazy<T>where
T: BorshSerialize,
Box<[u8]>: BorshDeserialize,
impl<T> BorshDeserialize for Lazy<T>where
T: BorshSerialize,
Box<[u8]>: BorshDeserialize,
sourceimpl<T> BorshSerialize for Lazy<T>where
T: BorshSerialize,
Box<[u8]>: BorshSerialize,
impl<T> BorshSerialize for Lazy<T>where
T: BorshSerialize,
Box<[u8]>: BorshSerialize,
sourceimpl<T> Debug for Lazy<T>where
T: Debug + BorshSerialize + BorshDeserialize,
impl<T> Debug for Lazy<T>where
T: Debug + BorshSerialize + BorshDeserialize,
sourceimpl<T> Deref for Lazy<T>where
T: BorshSerialize + BorshDeserialize,
impl<T> Deref for Lazy<T>where
T: BorshSerialize + BorshDeserialize,
sourceimpl<T> DerefMut for Lazy<T>where
T: BorshSerialize + BorshDeserialize,
impl<T> DerefMut for Lazy<T>where
T: BorshSerialize + BorshDeserialize,
sourceimpl<T> Drop for Lazy<T>where
T: BorshSerialize,
impl<T> Drop for Lazy<T>where
T: BorshSerialize,
sourceimpl<T> Ord for Lazy<T>where
T: Ord + BorshSerialize + BorshDeserialize,
impl<T> Ord for Lazy<T>where
T: Ord + BorshSerialize + BorshDeserialize,
1.21.0 · sourcefn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl<T> PartialEq<Lazy<T>> for Lazy<T>where
T: PartialEq + BorshSerialize + BorshDeserialize,
impl<T> PartialEq<Lazy<T>> for Lazy<T>where
T: PartialEq + BorshSerialize + BorshDeserialize,
sourceimpl<T> PartialOrd<Lazy<T>> for Lazy<T>where
T: PartialOrd + BorshSerialize + BorshDeserialize,
impl<T> PartialOrd<Lazy<T>> for Lazy<T>where
T: PartialOrd + BorshSerialize + BorshDeserialize,
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
sourcefn 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>where
T: Eq + BorshSerialize + BorshDeserialize,
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more