pub struct Dict<K, V> { /* private fields */ }Expand description
Typed dictionary with fixed length keys.
Implementations§
Source§impl<K, V> Dict<K, V>
impl<K, V> Dict<K, V>
Sourcepub fn cast_into<Q, T>(self) -> Dict<Q, T>where
Q: EquivalentRepr<K>,
T: EquivalentRepr<V>,
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.
Sourcepub fn cast_ref<Q, T>(&self) -> &Dict<Q, T>where
Q: EquivalentRepr<K>,
T: EquivalentRepr<V>,
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>
impl<K: DictKey, V> Dict<K, V>
Sourcepub fn load_from_root_ext(
slice: &mut CellSlice<'_>,
context: &dyn CellContext,
) -> Result<Self, Error>
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,
impl<K, V> Dict<K, V>where
K: StoreDictKey,
Source§impl<K, V> Dict<K, V>where
K: StoreDictKey,
impl<K, V> Dict<K, V>where
K: StoreDictKey,
Sourcepub fn get<'a: 'b, 'b, Q>(&'a self, key: Q) -> Result<Option<V>, Error>
pub fn get<'a: 'b, 'b, Q>(&'a self, key: Q) -> Result<Option<V>, Error>
Returns the value corresponding to the key.
Sourcepub fn get_raw<'a: 'b, 'b, Q>(
&'a self,
key: Q,
) -> Result<Option<CellSlice<'a>>, Error>where
Q: Borrow<K> + 'b,
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.
Sourcepub fn get_raw_owned<Q>(&self, key: Q) -> Result<Option<CellSliceParts>, Error>where
Q: Borrow<K>,
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.
Sourcepub fn remove<Q>(&mut self, key: Q) -> Result<Option<V>, Error>
pub fn remove<Q>(&mut self, key: Q) -> Result<Option<V>, Error>
Removes the value associated with key in dictionary. Returns an optional removed value.
The dict is rebuilt using an empty cell context.
Sourcepub fn remove_raw<Q>(&mut self, key: Q) -> Result<Option<CellSliceParts>, Error>where
Q: Borrow<K>,
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.
Sourcepub fn remove_min_raw(
&mut self,
signed: bool,
) -> Result<Option<(K, CellSliceParts)>, Error>where
K: LoadDictKey,
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.
Sourcepub fn remove_max_raw(
&mut self,
signed: bool,
) -> Result<Option<(K, CellSliceParts)>, Error>where
K: LoadDictKey,
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.
Sourcepub fn remove_bound_raw(
&mut self,
bound: DictBound,
signed: bool,
) -> Result<Option<(K, CellSliceParts)>, Error>where
K: LoadDictKey,
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.
Sourcepub fn split(&self) -> Result<(Self, Self), Error>
pub fn split(&self) -> Result<(Self, Self), Error>
Split dictionary into 2 dictionaries by the first key bit.
Sourcepub fn split_ext(
&self,
context: &dyn CellContext,
) -> Result<(Self, Self), Error>
pub fn split_ext( &self, context: &dyn CellContext, ) -> Result<(Self, Self), Error>
Split dictionary into 2 dictionaries by the first key bit.
Sourcepub fn split_by_prefix(
&self,
key_prefix: &CellSlice<'_>,
) -> Result<(Self, Self), Error>
pub fn split_by_prefix( &self, key_prefix: &CellSlice<'_>, ) -> Result<(Self, Self), Error>
Split dictionary into 2 dictionaries at the prefix.
Sourcepub fn split_by_prefix_ext(
&self,
key_prefix: &CellSlice<'_>,
context: &dyn CellContext,
) -> Result<(Self, Self), Error>
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.
Sourcepub fn merge_with_right_sibling(
&self,
right: &Dict<K, V>,
) -> Result<Self, Error>where
for<'a> V: Load<'a> + 'static,
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.
Sourcepub fn merge_with_right_sibling_ext(
&self,
right: &Dict<K, V>,
context: &dyn CellContext,
) -> Result<Self, Error>
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,
impl<K, V> Dict<K, V>where
K: StoreDictKey,
V: Store,
Sourcepub fn try_from_btree<Q, T>(sorted: &BTreeMap<Q, T>) -> Result<Self, Error>
pub fn try_from_btree<Q, T>(sorted: &BTreeMap<Q, T>) -> Result<Self, Error>
Builds a dictionary from a sorted collection.
Sourcepub fn try_from_sorted_slice<Q, T>(sorted: &[(Q, T)]) -> Result<Self, Error>
pub fn try_from_sorted_slice<Q, T>(sorted: &[(Q, T)]) -> Result<Self, Error>
Builds a dictionary from a sorted slice.
Sourcepub fn modify_with_sorted_iter<I>(&mut self, entries: I) -> Result<bool, Error>
pub fn modify_with_sorted_iter<I>(&mut self, entries: I) -> Result<bool, 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.
Sourcepub 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>
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>
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.
Sourcepub fn set<Q, T>(&mut self, key: Q, value: T) -> Result<bool, Error>
pub fn set<Q, T>(&mut self, key: Q, value: T) -> Result<bool, Error>
Sets the value associated with the key in the dictionary.
Use set_ext if you need to use a custom cell context.
Source§impl<K, V> Dict<K, V>where
K: DictKey,
impl<K, V> Dict<K, V>where
K: DictKey,
Sourcepub fn iter<'a>(&'a self) -> Iter<'a, K, V> ⓘwhere
V: Load<'a>,
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.
Sourcepub fn iter_union<'a>(&'a self, other: &'a Self) -> UnionIter<'a, K, V> ⓘwhere
V: Load<'a>,
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.
Sourcepub fn keys(&self) -> Keys<'_, K> ⓘ
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.
Sourcepub fn get_next<Q>(&self, key: Q, signed: bool) -> Result<Option<(K, V)>, Error>
pub fn get_next<Q>(&self, key: Q, signed: bool) -> Result<Option<(K, V)>, Error>
Computes the minimal key in dictionary that is lexicographically greater than key,
and returns it along with associated value as cell slice parts.
Sourcepub fn get_prev<Q>(&self, key: Q, signed: bool) -> Result<Option<(K, V)>, Error>
pub fn get_prev<Q>(&self, key: Q, signed: bool) -> Result<Option<(K, V)>, Error>
Computes the maximal key in dictionary that is lexicographically smaller than key,
and returns it along with associated value as cell slice parts.
Sourcepub fn get_or_next<Q>(
&self,
key: Q,
signed: bool,
) -> Result<Option<(K, V)>, Error>
pub fn get_or_next<Q>( &self, key: Q, signed: bool, ) -> Result<Option<(K, V)>, Error>
Computes the minimal key in dictionary that is lexicographically greater than key,
and returns it along with associated value as cell slice parts.
Source§impl<K, V> Dict<K, V>where
K: DictKey,
impl<K, V> Dict<K, V>where
K: DictKey,
Sourcepub fn values<'a>(&'a self) -> Values<'a, V> ⓘwhere
V: Load<'a>,
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.
Sourcepub fn get_min<'a>(&'a self, signed: bool) -> Result<Option<(K, V)>, Error>where
K: LoadDictKey,
V: Load<'a>,
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.
Sourcepub fn get_max<'a>(&'a self, signed: bool) -> Result<Option<(K, V)>, Error>where
K: LoadDictKey,
V: Load<'a>,
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.
Sourcepub fn get_bound_raw(
&self,
bound: DictBound,
signed: bool,
) -> Result<Option<(K, CellSlice<'_>)>, Error>where
K: LoadDictKey,
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.
Sourcepub fn remove_bound_raw_ext(
&mut self,
bound: DictBound,
signed: bool,
context: &dyn CellContext,
) -> Result<Option<(K, CellSliceParts)>, Error>where
K: LoadDictKey,
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,
impl<K, V> Dict<K, V>where
K: StoreDictKey,
Sourcepub fn remove_raw_ext<Q>(
&mut self,
key: Q,
context: &dyn CellContext,
) -> Result<Option<CellSliceParts>, Error>where
Q: Borrow<K>,
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.
Sourcepub fn raw_iter(&self) -> RawIter<'_> ⓘ
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.
Sourcepub fn raw_iter_union<'a>(&'a self, other: &'a Self) -> UnionRawIter<'a> ⓘ
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.
Sourcepub fn raw_keys(&self) -> RawKeys<'_> ⓘ
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,
impl<K, V> Dict<K, V>where
K: DictKey,
Sourcepub fn raw_values(&self) -> RawValues<'_> ⓘ
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,
impl<K, V> Dict<K, V>where
K: StoreDictKey,
V: Store,
Sourcepub fn set_ext<Q, T>(
&mut self,
key: Q,
value: T,
context: &dyn CellContext,
) -> Result<bool, Error>
pub fn set_ext<Q, T>( &mut self, key: Q, value: T, context: &dyn CellContext, ) -> Result<bool, Error>
Sets the value associated with the key in the dictionary.
Sourcepub fn replace_ext<Q, T>(
&mut self,
key: Q,
value: T,
context: &dyn CellContext,
) -> Result<bool, Error>
pub fn replace_ext<Q, T>( &mut self, key: Q, value: T, context: &dyn CellContext, ) -> Result<bool, Error>
Sets the value associated with the key in the dictionary only if the key was already present in it.
Trait Implementations§
Source§impl BlockSignatureExt for Dict<u16, BlockSignature>
impl BlockSignatureExt for Dict<u16, BlockSignature>
Source§impl<'de, K, V> Deserialize<'de> for Dict<K, V>
Available on crate feature serde only.
impl<'de, K, V> Deserialize<'de> for Dict<K, V>
serde only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<K, V> ExactSize for Dict<K, V>
impl<K, V> ExactSize for Dict<K, V>
Source§fn exact_size(&self) -> Size
fn exact_size(&self) -> Size
Source§impl From<Dict<u32, VarUint248>> for ExtraCurrencyCollection
impl From<Dict<u32, VarUint248>> for ExtraCurrencyCollection
Source§impl From<ExtraCurrencyCollection> for Dict<u32, VarUint248>
impl From<ExtraCurrencyCollection> for Dict<u32, VarUint248>
Source§fn from(value: ExtraCurrencyCollection) -> Self
fn from(value: ExtraCurrencyCollection) -> Self
Source§impl<K, V> Store for Dict<K, V>
impl<K, V> Store for Dict<K, V>
Source§fn store_into(
&self,
builder: &mut CellBuilder,
context: &dyn CellContext,
) -> Result<(), Error>
fn store_into( &self, builder: &mut CellBuilder, context: &dyn CellContext, ) -> Result<(), Error>
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>
impl<K, V> Sync for Dict<K, V>
impl<K, V> Unpin for Dict<K, V>
impl<K, V> !UnwindSafe for Dict<K, V>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
self to key and returns true if they are equal.