Struct near_sdk::collections::UnorderedSet
source · [−]pub struct UnorderedSet<T> { /* private fields */ }
Expand description
An iterable implementation of a set that stores its content directly on the trie.
Implementations
sourceimpl<T> UnorderedSet<T>
impl<T> UnorderedSet<T>
sourcepub fn len(&self) -> u64
pub fn len(&self) -> u64
Returns the number of elements in the set, also referred to as its size.
Examples
use near_sdk::collections::UnorderedSet;
let mut set: UnorderedSet<u8> = UnorderedSet::new(b"s");
assert_eq!(set.len(), 0);
set.insert(&1);
set.insert(&2);
assert_eq!(set.len(), 2);
sourcepub fn new<S>(prefix: S) -> Self where
S: IntoStorageKey,
pub fn new<S>(prefix: S) -> Self where
S: IntoStorageKey,
Create new map with zero elements. Use id
as a unique identifier.
Examples
use near_sdk::collections::UnorderedSet;
let mut set: UnorderedSet<u32> = UnorderedSet::new(b"s");
sourcepub fn insert_raw(&mut self, element_raw: &[u8]) -> bool
pub fn insert_raw(&mut self, element_raw: &[u8]) -> 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.
sourcepub fn remove_raw(&mut self, element_raw: &[u8]) -> bool
pub fn remove_raw(&mut self, element_raw: &[u8]) -> bool
Removes a value from the set. Returns whether the value was present in the set.
sourceimpl<T> UnorderedSet<T> where
T: BorshSerialize + BorshDeserialize,
impl<T> UnorderedSet<T> where
T: BorshSerialize + BorshDeserialize,
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::UnorderedSet;
let mut set: UnorderedSet<u8> = UnorderedSet::new(b"s");
assert_eq!(set.contains(&1), false);
set.insert(&1);
assert_eq!(set.contains(&1), 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::UnorderedSet;
let mut set: UnorderedSet<u8> = UnorderedSet::new(b"s");
assert_eq!(set.remove(&1), false);
set.insert(&1);
assert_eq!(set.remove(&1), true);
assert_eq!(set.contains(&1), false);
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::UnorderedSet;
let mut set: UnorderedSet<u8> = UnorderedSet::new(b"s");
assert_eq!(set.insert(&1), true);
assert_eq!(set.insert(&1), false);
assert_eq!(set.contains(&1), true);
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the map, removing all elements.
Examples
use near_sdk::collections::UnorderedSet;
let mut set: UnorderedSet<u8> = UnorderedSet::new(b"s");
set.insert(&1);
set.insert(&2);
set.clear();
assert_eq!(set.len(), 0);
pub fn extend<IT: IntoIterator<Item = T>>(&mut self, iter: IT)
Trait Implementations
sourceimpl<T> BorshDeserialize for UnorderedSet<T> where
Vec<u8>: BorshDeserialize,
Vector<T>: BorshDeserialize,
impl<T> BorshDeserialize for UnorderedSet<T> where
Vec<u8>: BorshDeserialize,
Vector<T>: BorshDeserialize,
sourceimpl<T> BorshSerialize for UnorderedSet<T> where
Vec<u8>: BorshSerialize,
Vector<T>: BorshSerialize,
impl<T> BorshSerialize for UnorderedSet<T> where
Vec<u8>: BorshSerialize,
Vector<T>: BorshSerialize,
sourceimpl<T> Debug for UnorderedSet<T> where
T: Debug + BorshSerialize + BorshDeserialize,
impl<T> Debug for UnorderedSet<T> where
T: Debug + BorshSerialize + BorshDeserialize,
Auto Trait Implementations
impl<T> RefUnwindSafe for UnorderedSet<T> where
T: RefUnwindSafe,
impl<T> Send for UnorderedSet<T> where
T: Send,
impl<T> Sync for UnorderedSet<T> where
T: Sync,
impl<T> Unpin for UnorderedSet<T> where
T: Unpin,
impl<T> UnwindSafe for UnorderedSet<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