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>

source

pub fn new<S>(element_prefix: S) -> Self
where 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");
source

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.

source

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,

source

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

let mut set: LookupSet<String> = LookupSet::new(b"s");
assert_eq!(set.insert(&"Element".into()), true);
assert_eq!(set.insert(&"Element".into()), false);
source

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

Trait Implementations§

source§

impl<T> BorshDeserialize for LookupSet<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 LookupSet<T>

source§

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

source§

impl<T> Debug for LookupSet<T>
where T: Debug + BorshSerialize,

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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> 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.