Struct near_sdk::collections::LookupSet
source · [−]pub struct LookupSet<T> { /* private fields */ }
Expand description
An non-iterable implementation of a set that stores its content directly on the trie.
Implementations
sourceimpl<T> LookupSet<T>
impl<T> LookupSet<T>
sourcepub fn new<S>(element_prefix: S) -> Self where
S: IntoStorageKey,
pub fn new<S>(element_prefix: S) -> Self where
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");
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);
pub fn extend<IT: IntoIterator<Item = T>>(&mut self, iter: IT)
Trait Implementations
sourceimpl<T> BorshDeserialize for LookupSet<T> where
Vec<u8>: BorshDeserialize,
impl<T> BorshDeserialize for LookupSet<T> where
Vec<u8>: BorshDeserialize,
sourceimpl<T> BorshSerialize for LookupSet<T> where
Vec<u8>: BorshSerialize,
impl<T> BorshSerialize for LookupSet<T> where
Vec<u8>: BorshSerialize,
Auto Trait Implementations
impl<T> RefUnwindSafe for LookupSet<T> where
T: RefUnwindSafe,
impl<T> Send for LookupSet<T> where
T: Send,
impl<T> Sync for LookupSet<T> where
T: Sync,
impl<T> Unpin for LookupSet<T> where
T: Unpin,
impl<T> UnwindSafe for LookupSet<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
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