Include builder methods on beancount-types

korrat
Dec 17, 2022, 9:03 AM
T2S6UAVJ6SVH5X326RLFZWF2LODSOEYAOQUHKW5D3NYNS43CU3AQC

Dependencies

  • [2] 2JBFREZG enable additional warnings
  • [*] YDK6X6PP add a library of important types for beancount

Change contents

  • edit in common/beancount-types/src/transaction.rs at line 7
    [2.3480]
    [2.3480]
    use tap::Tap as _;
  • edit in common/beancount-types/src/transaction.rs at line 13
    [4.147]
    [4.233]
    use crate::Link;
    use crate::MetadataKey;
    use crate::MetadataValue;
    use crate::TransactionMetadata;
  • edit in common/beancount-types/src/transaction.rs at line 29
    [4.465]
    [4.465]
    }
    impl Posting {
    pub fn on(account: impl Into<Account>) -> Self {
    let account = account.into();
    let (flag, amount, cost, price) = Default::default();
    Self {
    flag,
    account,
    amount,
    cost,
    price,
    }
    }
    }
    impl Posting {
    #[inline]
    pub fn clear_amount(&mut self) -> &mut Self {
    self.amount = Default::default();
    self
    }
    #[inline]
    pub fn clear_cost(&mut self) -> &mut Self {
    self.cost = Default::default();
    self
    }
    #[inline]
    pub fn clear_flag(&mut self) -> &mut Self {
    self.flag = Default::default();
    self
    }
    #[inline]
    pub fn clear_price(&mut self) -> &mut Self {
    self.price = Default::default();
    self
    }
    #[inline]
    pub fn complete(&mut self) -> &mut Self {
    self.set_flag(Flag::Complete)
    }
    #[inline]
    pub fn incomplete(&mut self) -> &mut Self {
    self.set_flag(Flag::Incomplete)
    }
    #[inline]
    pub fn set_account(&mut self, account: impl Into<Account>) -> &mut Self {
    self.account = account.into();
    self
    }
    #[inline]
    pub fn set_amount(&mut self, amount: Amount) -> &mut Self {
    self.amount = Some(amount);
    self
    }
    #[inline]
    pub fn set_cost(&mut self, cost: CostBasis) -> &mut Self {
    self.cost = Some(cost);
    self
    }
    #[inline]
    pub fn set_flag(&mut self, flag: Flag) -> &mut Self {
    self.flag = Some(flag);
    self
    }
    #[inline]
    pub fn set_price(&mut self, price: Amount) -> &mut Self {
    self.price = Some(price);
    self
    }
  • edit in common/beancount-types/src/transaction.rs at line 149
    [4.1244]
    [4.1244]
    // TODO consider using Cow
  • edit in common/beancount-types/src/transaction.rs at line 152
    [4.1276]
    [4.1276]
    // TODO consider using Cow
  • edit in common/beancount-types/src/transaction.rs at line 157
    [4.1312]
    [4.1312]
    // TODO consider using smallvecs
  • edit in common/beancount-types/src/transaction.rs at line 159
    [4.1344]
    [4.1344]
    }
    impl Transaction {
    pub fn on(date: Date) -> Self {
    let (flag, payee, narration, postings) = Default::default();
    Self {
    date,
    flag,
    payee,
    narration,
    postings,
    }
    }
  • edit in common/beancount-types/src/transaction.rs at line 175
    [4.1346]
    [4.1346]
    impl Transaction {
    #[inline]
    pub fn add_posting(&mut self, posting: Posting) -> &mut Self {
    self.postings.push(posting);
    self
    }
  • edit in common/beancount-types/src/transaction.rs at line 183
    [4.1347]
    [4.1347]
    #[inline]
    pub fn build_posting(
    &mut self,
    on: impl Into<Account>,
    block: impl FnOnce(&mut Posting),
    ) -> &mut Self {
    self.add_posting(Posting::on(on).tap_mut(block))
    }