pub struct UnorderedSet<T> { /* private fields */ }
Expand description

An iterable implementation of a set that stores its content directly on the trie.

Implementations§

source§

impl<T> UnorderedSet<T>

source

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);
source

pub fn is_empty(&self) -> bool

Returns true if the set contains no elements.

source

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");
source

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.

source

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.

source§

impl<T> UnorderedSet<T>

source

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);
source

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);
source

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);
source

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);
source

pub fn to_vec(&self) -> Vec<T>

Copies elements into an std::vec::Vec.

source

pub fn iter(&self) -> impl Iterator<Item = T> + '_

Iterate over deserialized elements.

source

pub fn extend<IT: IntoIterator<Item = T>>(&mut self, iter: IT)

source

pub fn as_vector(&self) -> &Vector<T>

Returns a view of elements as a vector. It’s sometimes useful to have random access to the elements.

Trait Implementations§

source§

impl<T> BorshDeserialize for UnorderedSet<T>

source§

fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self, Error>

source§

fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes.
source§

fn try_from_slice(v: &[u8]) -> Result<Self, Error>

Deserialize this instance from a slice of bytes.
source§

fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>
where R: Read,

source§

impl<T> BorshSerialize for UnorderedSet<T>
where T: BorshSerialize,

source§

fn serialize<W: Write>(&self, writer: &mut W) -> Result<(), Error>

source§

impl<T> Debug for UnorderedSet<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for UnorderedSet<T>

§

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§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.