Add type for raw price specs

korrat
Mar 19, 2024, 2:59 PM
576M5IPAWWEQSEJLYGM4WAFHC24P2MSOJIAWXJKXNMSXDXUVTUWAC

Dependencies

  • [2] UO34MAAG Refactor CSV-based Importers
  • [3] OILXIR24 Support metadata on postings
  • [4] NG5QXPZH Extract Account into separate crate
  • [5] XQHYMSDY Add importer for Union Investment transactions
  • [6] QRIJE4AQ add a simple pretty printer for beancount directives
  • [7] SJ6AFVZL remove const configuration in favor of runtime config
  • [8] XWHISGCP Extract Amount into separate crate
  • [9] T2S6UAVJ Include builder methods on beancount-types
  • [10] WS3UUOV3 Extract commodity type into separate crate
  • [11] PCHAKXNM Add an importer for Fidor account statements
  • [12] BDLVPDJZ Add a importer account for BW bank portfolios
  • [13] YDK6X6PP add a library of important types for beancount
  • [*] 2JBFREZG enable additional warnings
  • [*] I2P2FTLE add basic parser for german decimals
  • [*] SLTVZLYX Upgrade dependencies
  • [*] D6UTHZA4 add a simple writer for saving a set of directives to a tree of files

Change contents

  • edit in importers/uniondepot/src/lib.rs at line 16
    [4.532]
    [4.559]
    use beancount_types::PriceSpec;
  • replacement in importers/uniondepot/src/lib.rs at line 231
    [4.7559][4.7559:7598]()
    posting.price = price;
    [4.7559]
    [4.7598]
    posting.price = price.map(PriceSpec::from);
  • edit in importers/bw-bank/src/portfolio.rs at line 15
    [4.500]
    [4.500]
    use beancount_types::PriceSpec;
  • replacement in importers/bw-bank/src/portfolio.rs at line 176
    [4.5228][4.5228:5271]()
    posting.price = price;
    [4.5228]
    [4.5271]
    posting.price = price.map(PriceSpec::from);
  • edit in common/beancount-types/src/transaction.rs at line 7
    [15.3480]
    [4.0]
    use beancount_price_spec::PriceSpec;
  • replacement in common/beancount-types/src/transaction.rs at line 33
    [4.434][4.434:465]()
    pub price: Option<Amount>,
    [4.434]
    [3.0]
    pub price: Option<PriceSpec>,
  • replacement in common/beancount-types/src/transaction.rs at line 136
    [4.1697][4.1697:1793]()
    pub fn set_price(&mut self, price: Amount) -> &mut Self {
    self.price = Some(price);
    [4.1697]
    [4.1793]
    pub fn set_price(&mut self, price: impl Into<PriceSpec>) -> &mut Self {
    self.price = Some(price.into());
  • replacement in common/beancount-types/src/transaction.rs at line 166
    [4.1030][4.1030:1072]()
    write!(f, " @ {price}")?;
    [4.1030]
    [4.1072]
    write!(f, " {price}")?;
  • edit in common/beancount-types/src/lib.rs at line 11
    [4.1792]
    [4.2176]
    pub use beancount_price_spec::PriceSpec;
  • replacement in common/beancount-types/Cargo.toml at line 27
    [4.2285][4.1800:1853](),[4.1853][4.1919:1971](),[4.1971][4.1853:1908](),[4.1853][4.1853:1908]()
    beancount-account.path = "../../beancount/account"
    beancount-amount.path = "../../beancount/amount"
    beancount-commodity.path = "../../beancount/commodity"
    [4.2285]
    [4.2336]
    beancount-account.path = "../../beancount/account"
    beancount-amount.path = "../../beancount/amount"
    beancount-commodity.path = "../../beancount/commodity"
    beancount-price-spec.path = "../../beancount/price-spec"
  • replacement in common/beancount-pretty-printer/src/lib.rs at line 301
    [4.4924][4.4924:4975]()
    write!(self.inner, " @ {price}")?;
    [4.4924]
    [4.4975]
    write!(self.inner, " {price}")?;
  • file addition: price-spec (d--r------)
    [4.1]
  • file addition: src (d--r------)
    [0.759]
  • file addition: lib.rs (----------)
    [0.776]
    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)
    }
    }
  • file addition: Cargo.toml (----------)
    [0.759]
    [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"
  • edit in Cargo.lock at line 133
    [17.707]
    [2.37945]
    "hashbrown 0.14.3",
  • edit in Cargo.lock at line 357
    [18.5692]
    [18.5692]
    name = "beancount-price-spec"
    version = "0.0.0-dev.0"
    dependencies = [
    "beancount-amount",
    ]
    [[package]]
  • edit in Cargo.lock at line 389
    [4.2564]
    [4.26614]
    "beancount-price-spec",