Struct cml_chain::assets::utils::AssetBundle
source · pub struct AssetBundle<T>(/* private fields */);
Expand description
Bundle of assets within range of T, grouped by PolicyID then AssetName
Implementations§
source§impl<T> AssetBundle<T>
impl<T> AssetBundle<T>
sourcepub fn set(
&mut self,
policy_id: PolicyId,
asset_name: AssetName,
value: T
) -> Option<T>
pub fn set( &mut self, policy_id: PolicyId, asset_name: AssetName, value: T ) -> Option<T>
Set the value of policy_id:asset_name to value. Returns the previous value, or None if it didn’t exist
sourcepub fn get(&self, policy_id: &PolicyId, asset_name: &AssetName) -> Option<T>
pub fn get(&self, policy_id: &PolicyId, asset_name: &AssetName) -> Option<T>
Get the value of policy_id:asset_name if it exists.
sourcepub fn checked_add(&self, rhs: &Self) -> Result<Self, AssetArithmeticError>
pub fn checked_add(&self, rhs: &Self) -> Result<Self, AssetArithmeticError>
Adds to bundles together, checking value bounds. Does not modify self, and instead returns the result.
sourcepub fn checked_sub(&self, rhs: &Self) -> Result<Self, AssetArithmeticError>
pub fn checked_sub(&self, rhs: &Self) -> Result<Self, AssetArithmeticError>
Subtracts rhs from this bundle. This does not modify self, and instead returns the result. Use clamped_sub (ClampedSub trait) if you need to only try to remove assets when they exist and ignore them when they don’t.
source§impl AssetBundle<i64>
impl AssetBundle<i64>
sourcepub fn as_positive_multiasset(&self) -> MultiAsset
pub fn as_positive_multiasset(&self) -> MultiAsset
Returns the multiasset where only positive (minting) entries are present
sourcepub fn as_negative_multiasset(&self) -> MultiAsset
pub fn as_negative_multiasset(&self) -> MultiAsset
Returns the multiasset where only negative (burning) entries are present
Methods from Deref<Target = LinkedHashMap<K, V>>§
sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional
more elements to be inserted into the map. The
map may reserve more space to avoid frequent allocations.
§Panics
Panics if the new allocation size overflows usize.
sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity of the map as much as possible. It will drop down as much as possible while maintaining the internal rules and possibly leaving some space in accordance with the resize policy.
sourcepub fn entry(&mut self, k: K) -> Entry<'_, K, V, S>
pub fn entry(&mut self, k: K) -> Entry<'_, K, V, S>
Gets the given key’s corresponding entry in the map for in-place manipulation.
§Examples
use linked_hash_map::LinkedHashMap;
let mut letters = LinkedHashMap::new();
for ch in "a short treatise on fungi".chars() {
let counter = letters.entry(ch).or_insert(0);
*counter += 1;
}
assert_eq!(letters[&'s'], 2);
assert_eq!(letters[&'t'], 3);
assert_eq!(letters[&'u'], 1);
assert_eq!(letters.get(&'y'), None);
sourcepub fn entries(&mut self) -> Entries<'_, K, V, S>
pub fn entries(&mut self) -> Entries<'_, K, V, S>
Returns an iterator visiting all entries in insertion order.
Iterator element type is OccupiedEntry<K, V, S>
. Allows for removal
as well as replacing the entry.
§Examples
use linked_hash_map::LinkedHashMap;
let mut map = LinkedHashMap::new();
map.insert("a", 10);
map.insert("c", 30);
map.insert("b", 20);
{
let mut iter = map.entries();
let mut entry = iter.next().unwrap();
assert_eq!(&"a", entry.key());
*entry.get_mut() = 17;
}
assert_eq!(&17, map.get(&"a").unwrap());
sourcepub fn insert(&mut self, k: K, v: V) -> Option<V>
pub fn insert(&mut self, k: K, v: V) -> Option<V>
Inserts a key-value pair into the map. If the key already existed, the old value is returned.
§Examples
use linked_hash_map::LinkedHashMap;
let mut map = LinkedHashMap::new();
map.insert(1, "a");
map.insert(2, "b");
assert_eq!(map[&1], "a");
assert_eq!(map[&2], "b");
sourcepub fn contains_key<Q>(&self, k: &Q) -> bool
pub fn contains_key<Q>(&self, k: &Q) -> bool
Checks if the map contains the given key.
sourcepub fn get<Q>(&self, k: &Q) -> Option<&V>
pub fn get<Q>(&self, k: &Q) -> Option<&V>
Returns the value corresponding to the key in the map.
§Examples
use linked_hash_map::LinkedHashMap;
let mut map = LinkedHashMap::new();
map.insert(1, "a");
map.insert(2, "b");
map.insert(2, "c");
map.insert(3, "d");
assert_eq!(map.get(&1), Some(&"a"));
assert_eq!(map.get(&2), Some(&"c"));
sourcepub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
pub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
Returns the mutable reference corresponding to the key in the map.
§Examples
use linked_hash_map::LinkedHashMap;
let mut map = LinkedHashMap::new();
map.insert(1, "a");
map.insert(2, "b");
*map.get_mut(&1).unwrap() = "c";
assert_eq!(map.get(&1), Some(&"c"));
sourcepub fn get_refresh<Q>(&mut self, k: &Q) -> Option<&mut V>
pub fn get_refresh<Q>(&mut self, k: &Q) -> Option<&mut V>
Returns the value corresponding to the key in the map.
If value is found, it is moved to the end of the list. This operation can be used in implemenation of LRU cache.
§Examples
use linked_hash_map::LinkedHashMap;
let mut map = LinkedHashMap::new();
map.insert(1, "a");
map.insert(2, "b");
map.insert(3, "d");
assert_eq!(map.get_refresh(&2), Some(&mut "b"));
assert_eq!((&2, &"b"), map.iter().rev().next().unwrap());
sourcepub fn remove<Q>(&mut self, k: &Q) -> Option<V>
pub fn remove<Q>(&mut self, k: &Q) -> Option<V>
Removes and returns the value corresponding to the key from the map.
§Examples
use linked_hash_map::LinkedHashMap;
let mut map = LinkedHashMap::new();
map.insert(2, "a");
assert_eq!(map.remove(&1), None);
assert_eq!(map.remove(&2), Some("a"));
assert_eq!(map.remove(&2), None);
assert_eq!(map.len(), 0);
sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the maximum number of key-value pairs the map can hold without reallocating.
§Examples
use linked_hash_map::LinkedHashMap;
let mut map: LinkedHashMap<i32, &str> = LinkedHashMap::new();
let capacity = map.capacity();
sourcepub fn pop_front(&mut self) -> Option<(K, V)>
pub fn pop_front(&mut self) -> Option<(K, V)>
Removes the first entry.
Can be used in implementation of LRU cache.
§Examples
use linked_hash_map::LinkedHashMap;
let mut map = LinkedHashMap::new();
map.insert(1, 10);
map.insert(2, 20);
map.pop_front();
assert_eq!(map.get(&1), None);
assert_eq!(map.get(&2), Some(&20));
sourcepub fn front(&self) -> Option<(&K, &V)>
pub fn front(&self) -> Option<(&K, &V)>
Gets the first entry.
§Examples
use linked_hash_map::LinkedHashMap;
let mut map = LinkedHashMap::new();
map.insert(1, 10);
map.insert(2, 20);
assert_eq!(map.front(), Some((&1, &10)));
sourcepub fn pop_back(&mut self) -> Option<(K, V)>
pub fn pop_back(&mut self) -> Option<(K, V)>
Removes the last entry.
§Examples
use linked_hash_map::LinkedHashMap;
let mut map = LinkedHashMap::new();
map.insert(1, 10);
map.insert(2, 20);
map.pop_back();
assert_eq!(map.get(&1), Some(&10));
assert_eq!(map.get(&2), None);
sourcepub fn back(&self) -> Option<(&K, &V)>
pub fn back(&self) -> Option<(&K, &V)>
Gets the last entry.
§Examples
use linked_hash_map::LinkedHashMap;
let mut map = LinkedHashMap::new();
map.insert(1, 10);
map.insert(2, 20);
assert_eq!(map.back(), Some((&2, &20)));
sourcepub fn iter(&self) -> Iter<'_, K, V>
pub fn iter(&self) -> Iter<'_, K, V>
Returns a double-ended iterator visiting all key-value pairs in order of insertion.
Iterator element type is (&'a K, &'a V)
§Examples
use linked_hash_map::LinkedHashMap;
let mut map = LinkedHashMap::new();
map.insert("a", 10);
map.insert("c", 30);
map.insert("b", 20);
let mut iter = map.iter();
assert_eq!((&"a", &10), iter.next().unwrap());
assert_eq!((&"c", &30), iter.next().unwrap());
assert_eq!((&"b", &20), iter.next().unwrap());
assert_eq!(None, iter.next());
sourcepub fn iter_mut(&mut self) -> IterMut<'_, K, V>
pub fn iter_mut(&mut self) -> IterMut<'_, K, V>
Returns a double-ended iterator visiting all key-value pairs in order of insertion.
Iterator element type is (&'a K, &'a mut V)
§Examples
use linked_hash_map::LinkedHashMap;
let mut map = LinkedHashMap::new();
map.insert("a", 10);
map.insert("c", 30);
map.insert("b", 20);
{
let mut iter = map.iter_mut();
let mut entry = iter.next().unwrap();
assert_eq!(&"a", entry.0);
*entry.1 = 17;
}
assert_eq!(&17, map.get(&"a").unwrap());
sourcepub fn drain(&mut self) -> Drain<'_, K, V>
pub fn drain(&mut self) -> Drain<'_, K, V>
Clears the map, returning all key-value pairs as an iterator. Keeps the allocated memory for reuse.
If the returned iterator is dropped before being fully consumed, it drops the remaining key-value pairs. The returned iterator keeps a mutable borrow on the vector to optimize its implementation.
Current performance implications (why to use this over into_iter()):
- Clears the inner HashMap instead of dropping it
- Puts all drained nodes in the free-list instead of deallocating them
- Avoids deallocating the sentinel node
sourcepub fn keys(&self) -> Keys<'_, K, V>
pub fn keys(&self) -> Keys<'_, K, V>
Returns a double-ended iterator visiting all key in order of insertion.
§Examples
use linked_hash_map::LinkedHashMap;
let mut map = LinkedHashMap::new();
map.insert('a', 10);
map.insert('c', 30);
map.insert('b', 20);
let mut keys = map.keys();
assert_eq!(&'a', keys.next().unwrap());
assert_eq!(&'c', keys.next().unwrap());
assert_eq!(&'b', keys.next().unwrap());
assert_eq!(None, keys.next());
sourcepub fn values(&self) -> Values<'_, K, V>
pub fn values(&self) -> Values<'_, K, V>
Returns a double-ended iterator visiting all values in order of insertion.
§Examples
use linked_hash_map::LinkedHashMap;
let mut map = LinkedHashMap::new();
map.insert('a', 10);
map.insert('c', 30);
map.insert('b', 20);
let mut values = map.values();
assert_eq!(&10, values.next().unwrap());
assert_eq!(&30, values.next().unwrap());
assert_eq!(&20, values.next().unwrap());
assert_eq!(None, values.next());
Trait Implementations§
source§impl<T> ClampedSub for AssetBundle<T>
impl<T> ClampedSub for AssetBundle<T>
fn clamped_sub(&self, rhs: &Self) -> Self
source§impl<T: Clone> Clone for AssetBundle<T>
impl<T: Clone> Clone for AssetBundle<T>
source§fn clone(&self) -> AssetBundle<T>
fn clone(&self) -> AssetBundle<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<T: Debug> Debug for AssetBundle<T>
impl<T: Debug> Debug for AssetBundle<T>
source§impl<T: Default> Default for AssetBundle<T>
impl<T: Default> Default for AssetBundle<T>
source§fn default() -> AssetBundle<T>
fn default() -> AssetBundle<T>
source§impl<T> Deref for AssetBundle<T>
impl<T> Deref for AssetBundle<T>
§type Target = OrderedHashMap<ScriptHash, OrderedHashMap<AssetName, T>>
type Target = OrderedHashMap<ScriptHash, OrderedHashMap<AssetName, T>>
source§impl<T> DerefMut for AssetBundle<T>
impl<T> DerefMut for AssetBundle<T>
source§impl<'de, T> Deserialize<'de> for AssetBundle<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for AssetBundle<T>where
T: Deserialize<'de>,
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 From<AssetBundle<u64>> for Value
impl From<AssetBundle<u64>> for Value
source§fn from(multiasset: MultiAsset) -> Self
fn from(multiasset: MultiAsset) -> Self
source§impl<T> From<OrderedHashMap<ScriptHash, OrderedHashMap<AssetName, T>>> for AssetBundle<T>
impl<T> From<OrderedHashMap<ScriptHash, OrderedHashMap<AssetName, T>>> for AssetBundle<T>
source§fn from(bundle: OrderedHashMap<PolicyId, OrderedHashMap<AssetName, T>>) -> Self
fn from(bundle: OrderedHashMap<PolicyId, OrderedHashMap<AssetName, T>>) -> Self
source§impl<T: Hash> Hash for AssetBundle<T>
impl<T: Hash> Hash for AssetBundle<T>
source§impl<T: JsonSchema> JsonSchema for AssetBundle<T>
impl<T: JsonSchema> JsonSchema for AssetBundle<T>
source§fn schema_name() -> String
fn schema_name() -> String
source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
source§fn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref
keyword. Read moresource§impl<T: PartialEq> PartialEq for AssetBundle<T>
impl<T: PartialEq> PartialEq for AssetBundle<T>
source§fn eq(&self, other: &AssetBundle<T>) -> bool
fn eq(&self, other: &AssetBundle<T>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<T> PartialOrd for AssetBundle<T>
impl<T> PartialOrd for AssetBundle<T>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more