use core::ops::{Add, Sub, Mul}; #[cfg(feature = "std")] use zeroize::Zeroize; use scale::{Encode, Decode, MaxEncodedLen}; use scale_info::TypeInfo; #[cfg(feature = "std")] use serde::{Serialize, Deserialize}; use crate::{Coin, Amount}; /// The type used for balances (a Coin and Balance). #[derive(Clone, Copy, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)] #[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))] pub struct Balance { pub coin: Coin, pub amount: Amount, } impl Add for Balance { type Output = Balance; fn add(self, other: Amount) -> Balance { Balance { coin: self.coin, amount: self.amount + other } } } impl Sub for Balance { type Output = Balance; fn sub(self, other: Amount) -> Balance { Balance { coin: self.coin, amount: self.amount - other } } } impl Mul for Balance { type Output = Balance; fn mul(self, other: Amount) -> Balance { Balance { coin: self.coin, amount: self.amount * other } } }