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§
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 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.
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 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§
source§impl<T> BorshDeserialize for LookupSet<T>
impl<T> BorshDeserialize for LookupSet<T>
fn deserialize_reader<__R: Read>(reader: &mut __R) -> Result<Self, Error>
source§fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
source§fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>where
R: Read,
source§impl<T> BorshSerialize for LookupSet<T>
impl<T> BorshSerialize for LookupSet<T>
Auto Trait Implementations§
impl<T> Freeze for LookupSet<T>
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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more