core: implement display for all core types

This commit is contained in:
Bruno BELANYI 2022-08-23 14:29:27 +02:00
parent 6df9c9d7a9
commit 17e7bb9988

View file

@ -12,6 +12,12 @@ use serde_with::{serde_as, DisplayFromStr};
#[serde(transparent)]
pub struct ClientId(pub u16);
impl std::fmt::Display for ClientId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}
/// Transactions are identified by a globally unique id. 32 bit is sufficient for our puposes.
#[derive(
Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize,
@ -19,6 +25,12 @@ pub struct ClientId(pub u16);
#[serde(transparent)]
pub struct TxId(pub u32);
impl std::fmt::Display for TxId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}
/// Amounts are represented as exact decimals, up to four places past the decimal.
/// For ease of implementation, make use of [fpdec::Decimal] instead of implementing a custom
/// fixed-point number.
@ -31,6 +43,12 @@ impl TxAmount {
pub const ZERO: Self = Self(Dec!(0));
}
impl std::fmt::Display for TxAmount {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}
impl std::ops::Add<TxAmount> for TxAmount {
type Output = Self;