use crate::{amount::AmountCents, Amount}; use serde::{Deserialize, Serialize}; use std::fmt::Display; pub type AssetId = u32; /// An asset /// /// The asset definition is just a u32 number, which is meaningless for the /// code, as long as each asset has an unique id. /// /// The asset struct also has a precision, which is a u8 number (from 0-255) /// which is used by amount when converting the inner_amount to a human readable /// format. #[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] pub struct Asset { pub id: AssetId, pub(crate) precision: u8, } impl Asset { pub fn new_amount(&self, cents: AmountCents) -> Amount { Amount::new(*self, cents) } } impl Display for Asset { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.id) } }