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

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

Implementations

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

Returns true if the set contains no elements.

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

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.

Removes a value from the set. Returns whether the value was present in the set.

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

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

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

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

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

Iterate over deserialized elements.

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

Trait Implementations

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes. Read more
Deserialize this instance from a slice of bytes.
Serialize this instance into a vector of bytes.
Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.