pub struct LazyOption<T> { /* private fields */ }
Expand description

An persistent lazy option, that stores a value in the storage.

Implementations

Returns true if the value is present in the storage.

Returns true if the value is not present in the storage.

Create a new lazy option with the given storage_key and the initial value.

Examples
use near_sdk::collections::LazyOption;

let option: LazyOption<u32> = LazyOption::new(b"l", Some(&42));
let another_option: LazyOption<u32> = LazyOption::new(b"l", None);

Removes the value from storage without reading it. Returns whether the value was present.

Examples
use near_sdk::collections::LazyOption;

let mut option: LazyOption<u32> = LazyOption::new(b"l", Some(&42));
assert_eq!(option.remove(), true);
assert!(option.is_none());
assert_eq!(option.remove(), false);

Removes the value from storage and returns it as an option.

Examples
use near_sdk::collections::LazyOption;

let mut option: LazyOption<u32> = LazyOption::new(b"l", Some(&42));
assert_eq!(option.take(), Some(42));
assert!(option.is_none());
assert_eq!(option.take(), None);

Gets the value from storage and returns it as an option.

Examples
use near_sdk::collections::LazyOption;

let mut option: LazyOption<u32> = LazyOption::new(b"l", None);
assert_eq!(option.get(), None);
option.set(&42);
assert_eq!(option.get(), Some(42));
assert!(option.is_some());

Sets the value into the storage without reading the previous value and returns whether the previous value was present.

Examples
use near_sdk::collections::LazyOption;

let mut option: LazyOption<u32> = LazyOption::new(b"l", None);
assert_eq!(option.set(&42), false);
assert_eq!(option.set(&420), true);

Replaces the value in the storage and returns the previous value as an option.

Examples
use near_sdk::collections::LazyOption;

let mut option: LazyOption<u32> = LazyOption::new(b"l", None);
assert_eq!(option.replace(&42), None);
assert_eq!(option.replace(&420), Some(42));

Trait Implementations

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes. Read more
Deserialize this instance from a slice of bytes.
Serialize this instance into a vector of bytes.
Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.