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§

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>

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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T> Same for T

§

type Output = T

Should always be Self
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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more