Dict

Struct Dict 

Source
pub struct Dict<K, V> { /* private fields */ }
Expand description

Typed dictionary with fixed length keys.

Implementations§

Source§

impl<K, V> Dict<K, V>

Source

pub const fn new() -> Self

Creates an empty dictionary

Source

pub const fn from_raw(dict: Option<Cell>) -> Self

Creates a dictionary from a raw cell.

Source

pub const fn is_empty(&self) -> bool

Returns true if the dictionary contains no elements.

Source

pub const fn root(&self) -> &Option<Cell>

Returns the underlying root cell of the dictionary.

Source

pub fn into_root(self) -> Option<Cell>

Returns the underlying root cell of the dictionary.

Source

pub fn cast_into<Q, T>(self) -> Dict<Q, T>
where Q: EquivalentRepr<K>, T: EquivalentRepr<V>,

Converts into a dictionary with an equivalent value type.

Source

pub fn cast_ref<Q, T>(&self) -> &Dict<Q, T>
where Q: EquivalentRepr<K>, T: EquivalentRepr<V>,

Casts itself into a lazy loaded for an equivalent type.

Source§

impl<K: DictKey, V> Dict<K, V>

Source

pub fn load_from_root_ext( slice: &mut CellSlice<'_>, context: &dyn CellContext, ) -> Result<Self, Error>

Loads a non-empty dictionary from a root cell.

Source§

impl<K, V> Dict<K, V>
where K: StoreDictKey,

Source

pub fn contains_key<Q>(&self, key: Q) -> Result<bool, Error>
where Q: Borrow<K>,

Returns true if the dictionary contains a value for the specified key.

Source§

impl<K, V> Dict<K, V>
where K: StoreDictKey,

Source

pub fn get<'a: 'b, 'b, Q>(&'a self, key: Q) -> Result<Option<V>, Error>
where Q: Borrow<K> + 'b, V: Load<'a>,

Returns the value corresponding to the key.

Source

pub fn get_raw<'a: 'b, 'b, Q>( &'a self, key: Q, ) -> Result<Option<CellSlice<'a>>, Error>
where Q: Borrow<K> + 'b,

Returns the raw value corresponding to the key.

Source

pub fn get_raw_owned<Q>(&self, key: Q) -> Result<Option<CellSliceParts>, Error>
where Q: Borrow<K>,

Returns cell slice parts of the value corresponding to the key.

NOTE: Uses the default cell context.

Source

pub fn remove<Q>(&mut self, key: Q) -> Result<Option<V>, Error>
where Q: Borrow<K>, for<'a> V: Load<'a> + 'static,

Removes the value associated with key in dictionary. Returns an optional removed value.

The dict is rebuilt using an empty cell context.

Source

pub fn remove_raw<Q>(&mut self, key: Q) -> Result<Option<CellSliceParts>, Error>
where Q: Borrow<K>,

Removes the value associated with key in dictionary. Returns an optional removed value as cell slice parts.

The dict is rebuilt using an empty cell context.

Source

pub fn remove_min_raw( &mut self, signed: bool, ) -> Result<Option<(K, CellSliceParts)>, Error>
where K: LoadDictKey,

Removes the lowest key from the dict. Returns an optional removed key and value as cell slice parts.

Use remove_bound_ext if you need to use a custom cell context.

Source

pub fn remove_max_raw( &mut self, signed: bool, ) -> Result<Option<(K, CellSliceParts)>, Error>
where K: LoadDictKey,

Removes the largest key from the dict. Returns an optional removed key and value as cell slice parts.

Use remove_bound_ext if you need to use a custom cell context.

Source

pub fn remove_bound_raw( &mut self, bound: DictBound, signed: bool, ) -> Result<Option<(K, CellSliceParts)>, Error>
where K: LoadDictKey,

Removes the specified dict bound. Returns an optional removed key and value as cell slice parts.

Use remove_bound_ext if you need to use a custom cell context.

Source

pub fn split(&self) -> Result<(Self, Self), Error>

Split dictionary into 2 dictionaries by the first key bit.

Source

pub fn split_ext( &self, context: &dyn CellContext, ) -> Result<(Self, Self), Error>

Split dictionary into 2 dictionaries by the first key bit.

Source

pub fn split_by_prefix( &self, key_prefix: &CellSlice<'_>, ) -> Result<(Self, Self), Error>

Split dictionary into 2 dictionaries at the prefix.

Source

pub fn split_by_prefix_ext( &self, key_prefix: &CellSlice<'_>, context: &dyn CellContext, ) -> Result<(Self, Self), Error>

Split dictionary into 2 dictionaries at the prefix.

Source

pub fn merge_with_right_sibling( &self, right: &Dict<K, V>, ) -> Result<Self, Error>
where for<'a> V: Load<'a> + 'static,

Merge dictionary with its right sibling.

Source

pub fn merge_with_right_sibling_ext( &self, right: &Dict<K, V>, context: &dyn CellContext, ) -> Result<Self, Error>

Merge dictionary with its right sibling.

Source§

impl<K, V> Dict<K, V>
where K: StoreDictKey, V: Store,

Source

pub fn try_from_btree<Q, T>(sorted: &BTreeMap<Q, T>) -> Result<Self, Error>
where Q: Borrow<K>, T: Borrow<V>, K: Ord,

Builds a dictionary from a sorted collection.

Source

pub fn try_from_sorted_slice<Q, T>(sorted: &[(Q, T)]) -> Result<Self, Error>
where Q: Borrow<K>, T: Borrow<V>, K: Ord,

Builds a dictionary from a sorted slice.

Source

pub fn modify_with_sorted_iter<I>(&mut self, entries: I) -> Result<bool, Error>
where I: IntoIterator<Item = (K, Option<V>)>, K: Clone + Ord,

Applies a sorted list of inserts/removes to the dictionary. Use this when you have a large set of known changes.

Uses custom extracts for values.

Source

pub fn modify_with_sorted_iter_ext<T, I, FK, FV>( &mut self, entries: I, extract_key: FK, extract_value: FV, context: &dyn CellContext, ) -> Result<bool, Error>
where I: IntoIterator<Item = T>, K: Ord, for<'a> FK: FnMut(&'a T) -> K, FV: FnMut(T) -> Result<Option<V>, Error>,

Applies a sorted list of inserts/removes to the dictionary. Use this when you have a large set of known changes.

Uses custom extracts for values.

Source

pub fn set<Q, T>(&mut self, key: Q, value: T) -> Result<bool, Error>
where Q: Borrow<K>, T: Borrow<V>,

Sets the value associated with the key in the dictionary.

Use set_ext if you need to use a custom cell context.

Source

pub fn replace<Q, T>(&mut self, key: Q, value: T) -> Result<bool, Error>
where Q: Borrow<K>, T: Borrow<V>,

Sets the value associated with the key in the dictionary only if the key was already present in it.

Use replace_ext if you need to use a custom cell context.

Source

pub fn add<Q, T>(&mut self, key: Q, value: T) -> Result<bool, Error>
where Q: Borrow<K>, T: Borrow<V>,

Sets the value associated with key in dictionary, but only if it is not already present.

Use add_ext if you need to use a custom cell context.

Source§

impl<K, V> Dict<K, V>
where K: DictKey,

Source

pub fn iter<'a>(&'a self) -> Iter<'a, K, V>
where V: Load<'a>,

Gets an iterator over the entries of the dictionary, sorted by key. The iterator element type is Result<(K, V)>.

If the dictionary is invalid, finishes after the first invalid element, returning an error.

§Performance

In the current implementation, iterating over dictionary builds a key for each element. Use values or raw_values if you don’t need keys from an iterator.

Source

pub fn iter_union<'a>(&'a self, other: &'a Self) -> UnionIter<'a, K, V>
where V: Load<'a>,

Gets an iterator over the entries of two dictionaries, sorted by key. The iterator element type is Result<(K, Option<V>, Option<V>)>.

If the dictionary is invalid, finishes after the first invalid element, returning an error.

§Performance

In the current implementation, iterating over dictionary builds a key for each element.

Source

pub fn keys(&self) -> Keys<'_, K>

Gets an iterator over the keys of the dictionary, in sorted order. The iterator element type is Result<K>.

If the dictionary is invalid, finishes after the first invalid element, returning an error.

§Performance

In the current implementation, iterating over dictionary builds a key for each element. Use values if you don’t need keys from an iterator.

Source

pub fn get_next<Q>(&self, key: Q, signed: bool) -> Result<Option<(K, V)>, Error>
where Q: Borrow<K>, K: StoreDictKey + LoadDictKey, for<'a> V: Load<'a>,

Computes the minimal key in dictionary that is lexicographically greater than key, and returns it along with associated value as cell slice parts.

Source

pub fn get_prev<Q>(&self, key: Q, signed: bool) -> Result<Option<(K, V)>, Error>
where Q: Borrow<K>, K: StoreDictKey + LoadDictKey, for<'a> V: Load<'a>,

Computes the maximal key in dictionary that is lexicographically smaller than key, and returns it along with associated value as cell slice parts.

Source

pub fn get_or_next<Q>( &self, key: Q, signed: bool, ) -> Result<Option<(K, V)>, Error>
where Q: Borrow<K>, K: StoreDictKey + LoadDictKey, for<'a> V: Load<'a>,

Computes the minimal key in dictionary that is lexicographically greater than key, and returns it along with associated value as cell slice parts.

Source

pub fn get_or_prev<Q>( &self, key: Q, signed: bool, ) -> Result<Option<(K, V)>, Error>
where Q: Borrow<K>, K: StoreDictKey + LoadDictKey, for<'a> V: Load<'a>,

Computes the maximal key in dictionary that is lexicographically smaller than key, and returns it along with associated value as cell slice parts.

Source§

impl<K, V> Dict<K, V>
where K: DictKey,

Source

pub fn values<'a>(&'a self) -> Values<'a, V>
where V: Load<'a>,

Gets an iterator over the values of the dictionary, in order by key. The iterator element type is Result<V>.

If the dictionary is invalid, finishes after the first invalid element, returning an error.

Source

pub fn get_min<'a>(&'a self, signed: bool) -> Result<Option<(K, V)>, Error>
where K: LoadDictKey, V: Load<'a>,

Returns the lowest key and a value corresponding to the key.

Source

pub fn get_max<'a>(&'a self, signed: bool) -> Result<Option<(K, V)>, Error>
where K: LoadDictKey, V: Load<'a>,

Returns the lowest key and a value corresponding to the key.

Source

pub fn get_bound_raw( &self, bound: DictBound, signed: bool, ) -> Result<Option<(K, CellSlice<'_>)>, Error>
where K: LoadDictKey,

Finds the specified dict bound and returns a key and a raw value corresponding to the key.

Source

pub fn remove_bound_raw_ext( &mut self, bound: DictBound, signed: bool, context: &dyn CellContext, ) -> Result<Option<(K, CellSliceParts)>, Error>
where K: LoadDictKey,

Removes the specified dict bound. Returns an optional removed key and value as cell slice parts.

Key and dict are serialized using the provided cell context.

Source§

impl<K, V> Dict<K, V>
where K: StoreDictKey,

Source

pub fn remove_raw_ext<Q>( &mut self, key: Q, context: &dyn CellContext, ) -> Result<Option<CellSliceParts>, Error>
where Q: Borrow<K>,

Removes the value associated with key in dictionary. Returns an optional removed value as cell slice parts.

Dict is rebuild using the provided cell context.

Source

pub fn raw_iter(&self) -> RawIter<'_>

Gets an iterator over the raw entries of the dictionary, sorted by key. The iterator element type is Result<(CellBuilder, CellSlice)>.

If the dictionary is invalid, finishes after the first invalid element, returning an error.

§Performance

In the current implementation, iterating over dictionary builds a key for each element. Use values or raw_values if you don’t need keys from an iterator.

Source

pub fn raw_iter_union<'a>(&'a self, other: &'a Self) -> UnionRawIter<'a>

Gets an iterator over the raw entries of two dictionaries, sorted by key. The iterator element type is Result<(CellBuilder, Option<CellSlice>, Option<CellSlice>)>.

If the dictionary is invalid, finishes after the first invalid element, returning an error.

§Performance

In the current implementation, iterating over dictionary builds a key for each element.

Source

pub fn raw_keys(&self) -> RawKeys<'_>

Gets an iterator over the raw keys of the dictionary, in sorted order. The iterator element type is Result<CellBuilder>.

If the dictionary is invalid, finishes after the first invalid element, returning an error.

§Performance

In the current implementation, iterating over dictionary builds a key for each element. Use values or raw_values if you don’t need keys from an iterator.

Source§

impl<K, V> Dict<K, V>
where K: DictKey,

Source

pub fn raw_values(&self) -> RawValues<'_>

Gets an iterator over the raw values of the dictionary, in order by key. The iterator element type is Result<CellSlice>.

If the dictionary is invalid, finishes after the first invalid element, returning an error.

Source§

impl<K, V> Dict<K, V>
where K: StoreDictKey, V: Store,

Source

pub fn set_ext<Q, T>( &mut self, key: Q, value: T, context: &dyn CellContext, ) -> Result<bool, Error>
where Q: Borrow<K>, T: Borrow<V>,

Sets the value associated with the key in the dictionary.

Source

pub fn replace_ext<Q, T>( &mut self, key: Q, value: T, context: &dyn CellContext, ) -> Result<bool, Error>
where Q: Borrow<K>, T: Borrow<V>,

Sets the value associated with the key in the dictionary only if the key was already present in it.

Source

pub fn add_ext<Q, T>( &mut self, key: Q, value: T, context: &dyn CellContext, ) -> Result<bool, Error>
where Q: Borrow<K>, T: Borrow<V>,

Sets the value associated with key in dictionary, but only if it is not already present.

Trait Implementations§

Source§

impl BlockSignatureExt for Dict<u16, BlockSignature>

Source§

fn check_signatures<'a, I>(&self, list: I, data: &[u8]) -> Result<u64, Error>
where I: IntoIterator<Item = &'a ValidatorDescription, IntoIter: ExactSizeIterator>,

Verifies signatures for the specified data and the provided list of nodes.
Source§

impl<K, V> Clone for Dict<K, V>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K, V> Debug for Dict<K, V>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<K, V> Default for Dict<K, V>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de, K, V> Deserialize<'de> for Dict<K, V>
where K: Deserialize<'de> + Hash + Eq + StoreDictKey, V: Deserialize<'de> + Store,

Available on crate feature serde only.
Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<K, V> ExactSize for Dict<K, V>

Source§

fn exact_size(&self) -> Size

Exact size of the value when it is stored in a slice.
Source§

impl From<Dict<u32, VarUint248>> for ExtraCurrencyCollection

Source§

fn from(value: Dict<u32, VarUint248>) -> Self

Converts to this type from the input type.
Source§

impl From<ExtraCurrencyCollection> for Dict<u32, VarUint248>

Source§

fn from(value: ExtraCurrencyCollection) -> Self

Converts to this type from the input type.
Source§

impl<K, V> From<Option<Cell>> for Dict<K, V>

Source§

fn from(dict: Option<Cell>) -> Self

Converts to this type from the input type.
Source§

impl<'a, K, V> Load<'a> for Dict<K, V>

Source§

fn load_from(slice: &mut CellSlice<'a>) -> Result<Self, Error>

Tries to load itself from a cell slice.
Source§

impl<K, V> PartialEq for Dict<K, V>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<K, V> Serialize for Dict<K, V>
where K: Serialize + LoadDictKey, for<'a> V: Serialize + Load<'a>,

Available on crate feature serde only.
Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<K, V> Store for Dict<K, V>

Source§

fn store_into( &self, builder: &mut CellBuilder, context: &dyn CellContext, ) -> Result<(), Error>

Tries to store itself into the cell builder.
Source§

impl<K, V, Q, T> TryFrom<&BTreeMap<Q, T>> for Dict<K, V>
where Q: Borrow<K>, T: Borrow<V>, K: StoreDictKey + Ord, V: Store,

Source§

type Error = Error

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

fn try_from(value: &BTreeMap<Q, T>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<K, V, Q, T> TryFrom<BTreeMap<Q, T>> for Dict<K, V>
where Q: Borrow<K>, T: Borrow<V>, K: StoreDictKey + Ord, V: Store,

Source§

type Error = Error

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

fn try_from(value: BTreeMap<Q, T>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<K, V> Eq for Dict<K, V>

Auto Trait Implementations§

§

impl<K, V> Freeze for Dict<K, V>

§

impl<K, V> !RefUnwindSafe for Dict<K, V>

§

impl<K, V> Send for Dict<K, V>
where K: Send, V: Send,

§

impl<K, V> Sync for Dict<K, V>
where K: Sync, V: Sync,

§

impl<K, V> Unpin for Dict<K, V>
where K: Unpin, V: Unpin,

§

impl<K, V> !UnwindSafe for Dict<K, V>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compares self to key and returns true if they are equal.
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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

Source§

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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> EquivalentRepr<T> for T