From 75e25d3b179c233ef7d85866bc61166f5947ffa6 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Fri, 5 May 2023 16:58:29 +0200 Subject: [PATCH] Add more trait impls for Coins --- packages/std/src/coins.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/std/src/coins.rs b/packages/std/src/coins.rs index 1c8c263673..87cda52a65 100644 --- a/packages/std/src/coins.rs +++ b/packages/std/src/coins.rs @@ -52,6 +52,14 @@ impl TryFrom<&[Coin]> for Coins { } } +impl TryFrom<[Coin; N]> for Coins { + type Error = StdError; + + fn try_from(slice: [Coin; N]) -> StdResult { + slice.to_vec().try_into() + } +} + impl TryFrom for Coins { type Error = StdError; @@ -62,6 +70,12 @@ impl TryFrom for Coins { } } +impl From for Vec { + fn from(value: Coins) -> Self { + value.into_vec() + } +} + impl FromStr for Coins { type Err = StdError; @@ -111,6 +125,12 @@ impl fmt::Display for Coins { } } +impl PartialEq for Coins { + fn eq(&self, other: &Coin) -> bool { + self.0.len() == 1 && self.amount_of(&other.denom) == other.amount + } +} + impl Coins { /// Cast to Vec, while NOT consuming the original object pub fn to_vec(&self) -> Vec {