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§
Source§impl<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 unc_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.
Source§impl<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 unc_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 unc_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 unc_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);