Skip to main content

CanonicalAssets

Struct CanonicalAssets 

Source
pub struct CanonicalAssets(/* private fields */);

Implementations§

Source§

impl CanonicalAssets

Source

pub fn empty() -> CanonicalAssets

Source

pub fn from_class_and_amount(class: AssetClass, amount: i128) -> CanonicalAssets

Source

pub fn from_naked_amount(amount: i128) -> CanonicalAssets

Source

pub fn from_named_asset(asset_name: &[u8], amount: i128) -> CanonicalAssets

Source

pub fn from_defined_asset( policy: &[u8], asset_name: &[u8], amount: i128, ) -> CanonicalAssets

Source

pub fn from_asset( policy: Option<&[u8]>, name: Option<&[u8]>, amount: i128, ) -> CanonicalAssets

Source

pub fn classes(&self) -> HashSet<AssetClass>

Source

pub fn naked_amount(&self) -> Option<i128>

Source

pub fn asset_amount2(&self, policy: &[u8], name: &[u8]) -> Option<i128>

Source

pub fn asset_amount(&self, asset: &AssetClass) -> Option<i128>

Source

pub fn contains_total(&self, other: &CanonicalAssets) -> bool

Source

pub fn contains_some(&self, other: &CanonicalAssets) -> bool

Source

pub fn is_empty(&self) -> bool

Source

pub fn is_empty_or_negative(&self) -> bool

Source

pub fn is_only_naked(&self) -> bool

Source

pub fn as_homogenous_asset(&self) -> Option<(AssetClass, i128)>

Methods from Deref<Target = HashMap<AssetClass, i128>>§

1.0.0 · Source

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 · Source

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 · Source

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 · Source

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 · Source

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 · Source

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 · Source

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 · Source

pub fn get<Q>(&self, k: &Q) -> Option<&V>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

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 · Source

pub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K, &V)>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

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 &K stored key value from a borrowed &Q lookup 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 · Source

pub fn contains_key<Q>(&self, k: &Q) -> bool
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

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

Source§

type Output = CanonicalAssets

The resulting type after applying the + operator.
Source§

fn add(self, other: CanonicalAssets) -> CanonicalAssets

Performs the + operation. Read more
Source§

impl Clone for CanonicalAssets

Source§

fn clone(&self) -> CanonicalAssets

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 Debug for CanonicalAssets

Source§

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

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

impl Default for CanonicalAssets

Source§

fn default() -> CanonicalAssets

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

impl Deref for CanonicalAssets

Source§

type Target = HashMap<AssetClass, i128>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &<CanonicalAssets as Deref>::Target

Dereferences the value.
Source§

impl<'de> Deserialize<'de> for CanonicalAssets

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<CanonicalAssets, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

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

impl Display for CanonicalAssets

Source§

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

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

impl From<AssetExpr> for CanonicalAssets

Source§

fn from(asset: AssetExpr) -> CanonicalAssets

Converts to this type from the input type.
Source§

impl From<CanonicalAssets> for HashMap<AssetClass, i128>

Source§

fn from(assets: CanonicalAssets) -> HashMap<AssetClass, i128>

Converts to this type from the input type.
Source§

impl From<CanonicalAssets> for Vec<AssetExpr>

Source§

fn from(assets: CanonicalAssets) -> Vec<AssetExpr>

Converts to this type from the input type.
Source§

impl From<Vec<AssetExpr>> for CanonicalAssets

Source§

fn from(assets: Vec<AssetExpr>) -> CanonicalAssets

Converts to this type from the input type.
Source§

impl IntoIterator for CanonicalAssets

Source§

type Item = (AssetClass, i128)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<AssetClass, i128>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <CanonicalAssets as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl Neg for CanonicalAssets

Source§

type Output = CanonicalAssets

The resulting type after applying the - operator.
Source§

fn neg(self) -> CanonicalAssets

Performs the unary - operation. Read more
Source§

impl PartialEq for CanonicalAssets

Source§

fn eq(&self, other: &CanonicalAssets) -> 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 Serialize for CanonicalAssets

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

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

impl Sub for CanonicalAssets

Source§

type Output = CanonicalAssets

The resulting type after applying the - operator.
Source§

fn sub(self, other: CanonicalAssets) -> CanonicalAssets

Performs the - operation. Read more
Source§

impl Eq for CanonicalAssets

Source§

impl StructuralPartialEq for CanonicalAssets

Auto Trait Implementations§

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> Arithmetic for T

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<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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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>,