Skip to content

Commit

Permalink
Add more trait impls for Coins
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed May 5, 2023
1 parent 3d860f8 commit 75e25d3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/std/src/coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ impl TryFrom<&[Coin]> for Coins {
}
}

impl<const N: usize> TryFrom<[Coin; N]> for Coins {
type Error = StdError;

fn try_from(slice: [Coin; N]) -> StdResult<Self> {
slice.to_vec().try_into()
}
}

impl TryFrom<Coin> for Coins {
type Error = StdError;

Expand All @@ -62,6 +70,12 @@ impl TryFrom<Coin> for Coins {
}
}

impl From<Coins> for Vec<Coin> {
fn from(value: Coins) -> Self {
value.into_vec()
}
}

impl FromStr for Coins {
type Err = StdError;

Expand Down Expand Up @@ -111,6 +125,12 @@ impl fmt::Display for Coins {
}
}

impl PartialEq<Coin> for Coins {
fn eq(&self, other: &Coin) -> bool {
self.0.len() == 1 && self.amount_of(&other.denom) == other.amount
}
}

impl Coins {
/// Cast to Vec<Coin>, while NOT consuming the original object
pub fn to_vec(&self) -> Vec<Coin> {
Expand Down

0 comments on commit 75e25d3

Please sign in to comment.