pub struct CanonicalAssets(/* private fields */);Implementations§
Source§impl CanonicalAssets
impl CanonicalAssets
pub fn empty() -> CanonicalAssets
pub fn from_class_and_amount(class: AssetClass, amount: i128) -> CanonicalAssets
pub fn from_naked_amount(amount: i128) -> CanonicalAssets
pub fn from_named_asset(asset_name: &[u8], amount: i128) -> CanonicalAssets
pub fn from_defined_asset( policy: &[u8], asset_name: &[u8], amount: i128, ) -> CanonicalAssets
pub fn from_asset( policy: Option<&[u8]>, name: Option<&[u8]>, amount: i128, ) -> CanonicalAssets
pub fn classes(&self) -> HashSet<AssetClass>
pub fn naked_amount(&self) -> Option<i128>
pub fn asset_amount2(&self, policy: &[u8], name: &[u8]) -> Option<i128>
pub fn asset_amount(&self, asset: &AssetClass) -> Option<i128>
pub fn contains_total(&self, other: &CanonicalAssets) -> bool
pub fn contains_some(&self, other: &CanonicalAssets) -> bool
pub fn is_empty(&self) -> bool
pub fn is_empty_or_negative(&self) -> bool
pub fn is_only_naked(&self) -> bool
pub fn as_homogenous_asset(&self) -> Option<(AssetClass, i128)>
Methods from Deref<Target = HashMap<AssetClass, i128>>§
1.0.0 · Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of elements the map can hold without reallocating.
This number is a lower bound; the HashMap<K, V> might be able to hold
more, but is guaranteed to be able to hold at least this many.
§Examples
use std::collections::HashMap;
let map: HashMap<i32, i32> = HashMap::with_capacity(100);
assert!(map.capacity() >= 100);1.0.0 · Sourcepub fn keys(&self) -> Keys<'_, K, V>
pub fn keys(&self) -> Keys<'_, K, V>
An iterator visiting all keys in arbitrary order.
The iterator element type is &'a K.
§Examples
use std::collections::HashMap;
let map = HashMap::from([
("a", 1),
("b", 2),
("c", 3),
]);
for key in map.keys() {
println!("{key}");
}§Performance
In the current implementation, iterating over keys takes O(capacity) time instead of O(len) because it internally visits empty buckets too.
1.0.0 · Sourcepub fn values(&self) -> Values<'_, K, V>
pub fn values(&self) -> Values<'_, K, V>
An iterator visiting all values in arbitrary order.
The iterator element type is &'a V.
§Examples
use std::collections::HashMap;
let map = HashMap::from([
("a", 1),
("b", 2),
("c", 3),
]);
for val in map.values() {
println!("{val}");
}§Performance
In the current implementation, iterating over values takes O(capacity) time instead of O(len) because it internally visits empty buckets too.
1.0.0 · Sourcepub fn iter(&self) -> Iter<'_, K, V>
pub fn iter(&self) -> Iter<'_, K, V>
An iterator visiting all key-value pairs in arbitrary order.
The iterator element type is (&'a K, &'a V).
§Examples
use std::collections::HashMap;
let map = HashMap::from([
("a", 1),
("b", 2),
("c", 3),
]);
for (key, val) in map.iter() {
println!("key: {key} val: {val}");
}§Performance
In the current implementation, iterating over map takes O(capacity) time instead of O(len) because it internally visits empty buckets too.
1.0.0 · Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the map.
§Examples
use std::collections::HashMap;
let mut a = HashMap::new();
assert_eq!(a.len(), 0);
a.insert(1, "a");
assert_eq!(a.len(), 1);1.0.0 · Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the map contains no elements.
§Examples
use std::collections::HashMap;
let mut a = HashMap::new();
assert!(a.is_empty());
a.insert(1, "a");
assert!(!a.is_empty());1.9.0 · Sourcepub fn hasher(&self) -> &S
pub fn hasher(&self) -> &S
Returns a reference to the map’s BuildHasher.
§Examples
use std::collections::HashMap;
use std::hash::RandomState;
let hasher = RandomState::new();
let map: HashMap<i32, i32> = HashMap::with_hasher(hasher);
let hasher: &RandomState = map.hasher();1.0.0 · Sourcepub fn get<Q>(&self, k: &Q) -> Option<&V>
pub fn get<Q>(&self, k: &Q) -> Option<&V>
Returns a reference to the value corresponding to the key.
The key may be any borrowed form of the map’s key type, but
Hash and Eq on the borrowed form must match those for
the key type.
§Examples
use std::collections::HashMap;
let mut map = HashMap::new();
map.insert(1, "a");
assert_eq!(map.get(&1), Some(&"a"));
assert_eq!(map.get(&2), None);1.40.0 · Sourcepub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K, &V)>
pub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K, &V)>
Returns the key-value pair corresponding to the supplied key. This is potentially useful:
- for key types where non-identical keys can be considered equal;
- for getting the
&Kstored key value from a borrowed&Qlookup key; or - for getting a reference to a key with the same lifetime as the collection.
The supplied key may be any borrowed form of the map’s key type, but
Hash and Eq on the borrowed form must match those for
the key type.
§Examples
use std::collections::HashMap;
use std::hash::{Hash, Hasher};
#[derive(Clone, Copy, Debug)]
struct S {
id: u32,
name: &'static str, // ignored by equality and hashing operations
}
impl PartialEq for S {
fn eq(&self, other: &S) -> bool {
self.id == other.id
}
}
impl Eq for S {}
impl Hash for S {
fn hash<H: Hasher>(&self, state: &mut H) {
self.id.hash(state);
}
}
let j_a = S { id: 1, name: "Jessica" };
let j_b = S { id: 1, name: "Jess" };
let p = S { id: 2, name: "Paul" };
assert_eq!(j_a, j_b);
let mut map = HashMap::new();
map.insert(j_a, "Paris");
assert_eq!(map.get_key_value(&j_a), Some((&j_a, &"Paris")));
assert_eq!(map.get_key_value(&j_b), Some((&j_a, &"Paris"))); // the notable case
assert_eq!(map.get_key_value(&p), None);1.0.0 · Sourcepub fn contains_key<Q>(&self, k: &Q) -> bool
pub fn contains_key<Q>(&self, k: &Q) -> bool
Returns true if the map contains a value for the specified key.
The key may be any borrowed form of the map’s key type, but
Hash and Eq on the borrowed form must match those for
the key type.
§Examples
use std::collections::HashMap;
let mut map = HashMap::new();
map.insert(1, "a");
assert_eq!(map.contains_key(&1), true);
assert_eq!(map.contains_key(&2), false);Trait Implementations§
Source§impl Add for CanonicalAssets
impl Add for CanonicalAssets
Source§type Output = CanonicalAssets
type Output = CanonicalAssets
+ operator.Source§fn add(self, other: CanonicalAssets) -> CanonicalAssets
fn add(self, other: CanonicalAssets) -> CanonicalAssets
+ operation. Read moreSource§impl Clone for CanonicalAssets
impl Clone for CanonicalAssets
Source§fn clone(&self) -> CanonicalAssets
fn clone(&self) -> CanonicalAssets
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CanonicalAssets
impl Debug for CanonicalAssets
Source§impl Default for CanonicalAssets
impl Default for CanonicalAssets
Source§fn default() -> CanonicalAssets
fn default() -> CanonicalAssets
Source§impl Deref for CanonicalAssets
impl Deref for CanonicalAssets
Source§impl<'de> Deserialize<'de> for CanonicalAssets
impl<'de> Deserialize<'de> for CanonicalAssets
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<CanonicalAssets, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<CanonicalAssets, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Display for CanonicalAssets
impl Display for CanonicalAssets
Source§impl From<AssetExpr> for CanonicalAssets
impl From<AssetExpr> for CanonicalAssets
Source§fn from(asset: AssetExpr) -> CanonicalAssets
fn from(asset: AssetExpr) -> CanonicalAssets
Source§impl From<CanonicalAssets> for HashMap<AssetClass, i128>
impl From<CanonicalAssets> for HashMap<AssetClass, i128>
Source§fn from(assets: CanonicalAssets) -> HashMap<AssetClass, i128>
fn from(assets: CanonicalAssets) -> HashMap<AssetClass, i128>
Source§impl IntoIterator for CanonicalAssets
impl IntoIterator for CanonicalAssets
Source§type Item = (AssetClass, i128)
type Item = (AssetClass, i128)
Source§fn into_iter(self) -> <CanonicalAssets as IntoIterator>::IntoIter
fn into_iter(self) -> <CanonicalAssets as IntoIterator>::IntoIter
Source§impl Neg for CanonicalAssets
impl Neg for CanonicalAssets
Source§type Output = CanonicalAssets
type Output = CanonicalAssets
- operator.Source§fn neg(self) -> CanonicalAssets
fn neg(self) -> CanonicalAssets
- operation. Read moreSource§impl PartialEq for CanonicalAssets
impl PartialEq for CanonicalAssets
Source§impl Serialize for CanonicalAssets
impl Serialize for CanonicalAssets
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Source§impl Sub for CanonicalAssets
impl Sub for CanonicalAssets
Source§type Output = CanonicalAssets
type Output = CanonicalAssets
- operator.Source§fn sub(self, other: CanonicalAssets) -> CanonicalAssets
fn sub(self, other: CanonicalAssets) -> CanonicalAssets
- operation. Read more