Struct near_sdk::collections::LookupSet
source · pub struct LookupSet<T> { /* private fields */ }
Expand description
A non-iterable implementation of a set that stores its content directly on the storage trie.
This set stores the values under a hash of the set’s prefix
and BorshSerialize
of the
value.
Implementations
sourceimpl<T> LookupSet<T>
impl<T> LookupSet<T>
sourcepub fn new<S>(element_prefix: S) -> Selfwhere
S: IntoStorageKey,
pub fn new<S>(element_prefix: S) -> Selfwhere
S: IntoStorageKey,
Create a new map. Use element_prefix
as a unique prefix for trie keys.
Examples
use near_sdk::collections::LookupSet;
let mut set: LookupSet<u32> = LookupSet::new(b"s");
sourcepub fn insert_raw(&mut self, element_raw: &[u8]) -> bool
pub fn insert_raw(&mut self, element_raw: &[u8]) -> bool
Inserts a serialized element into the set.
If the set did not have this value present, true
is returned.
If the set did have this value present, false
is returned.
sourcepub fn remove_raw(&mut self, element_raw: &[u8]) -> bool
pub fn remove_raw(&mut self, element_raw: &[u8]) -> bool
Removes a serialized element from the set. Returns true if the element was present in the set.
sourceimpl<T> LookupSet<T>where
T: BorshSerialize,
impl<T> LookupSet<T>where
T: BorshSerialize,
sourcepub fn contains(&self, element: &T) -> bool
pub fn contains(&self, element: &T) -> bool
Returns true if the set contains an element.
Examples
use near_sdk::collections::LookupSet;
let mut set: LookupSet<String> = LookupSet::new(b"s");
assert_eq!(set.contains(&"Element".into()), false);
set.insert(&"Element".into());
assert_eq!(set.contains(&"Element".into()), true);
sourcepub fn remove(&mut self, element: &T) -> bool
pub fn remove(&mut self, element: &T) -> bool
Removes a value from the set. Returns whether the value was present in the set.
Examples
use near_sdk::collections::LookupSet;
let mut set: LookupSet<String> = LookupSet::new(b"s");
assert_eq!(set.remove(&"Element".into()), false);
set.insert(&"Element".into());
assert_eq!(set.remove(&"Element".into()), true);
sourcepub fn insert(&mut self, element: &T) -> bool
pub fn insert(&mut self, element: &T) -> bool
Adds a value to the set.
If the set did not have this value present, true
is returned.
If the set did have this value present, false
is returned.
Examples
use near_sdk::collections::LookupSet;
let mut set: LookupSet<String> = LookupSet::new(b"s");
assert_eq!(set.insert(&"Element".into()), true);
assert_eq!(set.insert(&"Element".into()), false);