576M5IPAWWEQSEJLYGM4WAFHC24P2MSOJIAWXJKXNMSXDXUVTUWAC
UO34MAAGCLHTUGNRZQUNIS32ZE354N72IMGZ76THUBKR7TDT6L2QC
OILXIR24AFYF4OXRBEFFSCNUJ56P2FI5UOT6NIVCR72QJIRSWUQAC
XQHYMSDYDG3MFDUEGXADTNXA4B7AQRSYA5JCP3S3KQYL527DORHQC
BDLVPDJZU5BPXRS5DTAUPJ5H6JWURRGS2NKKNCA43HGQGRFIKGIAC
2JBFREZGJ2PST2DE3ZVDQADXAOFXBYPMSFTG7C65GDKLOZGETTGAC
T2S6UAVJ6SVH5X326RLFZWF2LODSOEYAOQUHKW5D3NYNS43CU3AQC
YDK6X6PPD42DMLFGF6OO2O3G7GA4Z2PCIDJIREHX6XNX2NYEBJSQC
WS3UUOV3DGSOZSN4V2O6YZDFO3M4NIC6BCYWGGEHFBCV4KZJPQHAC
NG5QXPZH5M5EMEQOUSI3VVFB4ORIARTE7WSVEHFG7NJ2S4MTAYFQC
XWHISGCP3WZJHEQXEFFGHR5JDVOD7NMRH5ZPWFVTWQPA5XJBZKNQC
QRIJE4AQWN7A7O2CO7FXRV4FXZ5RHONQKRGHYXAD7WSECJYK2MFAC
SLTVZLYXPHYVACXUOKWGVI3MV6IJBT22Y4NYRBQDVDYULCDSJ6SAC
I2P2FTLEKLICJKHQ3FHOLRQRQYGZCJTCTU2MWXU2TMIRIKG6YFCQC
D6UTHZA4XNAR2PTG4YEZFNNH3OTSNOWGDSVBYDRE5R2YSV7MPN6AC
beancount-account.path = "../../beancount/account"
beancount-amount.path = "../../beancount/amount"
beancount-commodity.path = "../../beancount/commodity"
beancount-account.path = "../../beancount/account"
beancount-amount.path = "../../beancount/amount"
beancount-commodity.path = "../../beancount/commodity"
beancount-price-spec.path = "../../beancount/price-spec"
use core::fmt::Display;
use beancount_amount::Amount;
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum PriceSpec {
PerUnit(Amount),
Total(Amount),
}
impl PriceSpec {
pub const fn amount(&self) -> Amount {
let (Self::PerUnit(amount) | Self::Total(amount)) = self;
*amount
}
}
impl Display for PriceSpec {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let symbol = match self {
Self::PerUnit(_) => "@",
Self::Total(_) => "@@",
};
let amount = self.amount();
write!(f, "{symbol} {amount}")
}
}
impl From<Amount> for PriceSpec {
fn from(amount: Amount) -> Self {
Self::PerUnit(amount)
}
}
[package]
name = "beancount-price-spec"
authors.workspace = true
edition.workspace = true
publish.workspace = true
rust-version.workspace = true
version.workspace = true
[dependencies]
# Workspace dependencies
beancount-amount.path = "../amount"