Implement metadata & price directives
Dependencies
- [2]
VM4ZH5WDHandle transaction metadata when pretty printing - [3]
X6YJF46GRespect directive order when writing trees - [4]
YBARPI2BMake account templates owned - [5]
6MYJDQ3IHandle price directives - [6]
MG46NYACenable deserialization of configuration for common utilities - [7]
2NYDNXH7Use OS dependent path separator when constructing paths in tree writer - [8]
QRIJE4AQadd a simple pretty printer for beancount directives - [9]
SMBQYFPGEnable access to timestamps for directives - [10]
SEEWF7KXImplement metadata on transactions - [11]
ND7GASJ4track current column position when writing - [12]
YDK6X6PPadd a library of important types for beancount - [13]
T2S6UAVJInclude builder methods on beancount-types - [14]
R7S2CWF7Add type for account segments - [15]
D6UTHZA4add a simple writer for saving a set of directives to a tree of files - [16]
SJ6AFVZLremove const configuration in favor of runtime config - [17]
2JBFREZGenable additional warnings - [18]
ENLUNKU5Make PrettyPrinterConfig public - [*]
W3MWSSJ7Add a templating engine for accounts - [*]
UESS5YZEmigrate dependencies into workspace manifest
Change contents
- edit in common/beancount-types/src/transaction.rs at line 12
use crate::Acc; - edit in common/beancount-types/src/transaction.rs at line 17
use crate::LinkSet; - edit in common/beancount-types/src/transaction.rs at line 19
use crate::MetadataMap; - edit in common/beancount-types/src/transaction.rs at line 21
use crate::TransactionMetadata; - replacement in common/beancount-types/src/transaction.rs at line 53
self.amount = Default::default();self.amount = None; - replacement in common/beancount-types/src/transaction.rs at line 59
self.cost = Default::default();self.cost = None; - replacement in common/beancount-types/src/transaction.rs at line 65
self.flag = Default::default();self.flag = None; - replacement in common/beancount-types/src/transaction.rs at line 71
self.price = Default::default();self.price = None; - replacement in common/beancount-types/src/transaction.rs at line 159
pub metadata: TransactionMetadata,pub links: LinkSet,pub meta: MetadataMap, - replacement in common/beancount-types/src/transaction.rs at line 169
let (flag, metadata, payee, narration, postings) = Default::default();let (flag, links, meta, payee, narration, postings) = Default::default(); - replacement in common/beancount-types/src/transaction.rs at line 176
metadata,links,meta, - replacement in common/beancount-types/src/transaction.rs at line 191
pub fn add_key_value(pub fn add_meta( - replacement in common/beancount-types/src/transaction.rs at line 196
self.metadata.add_key_value(key, value);self.meta.insert(key.into(), value.into()); - replacement in common/beancount-types/src/transaction.rs at line 202
self.metadata.add_link(link);self.links.insert(link.into()); - replacement in common/beancount-types/src/transaction.rs at line 216
pub fn clear_metadata(&mut self) -> &mut Self {self.metadata = Default::default();pub fn clear_meta(&mut self) -> &mut Self {self.meta.clear(); - replacement in common/beancount-types/src/transaction.rs at line 223
self.narration = Default::default();self.narration = None; - replacement in common/beancount-types/src/transaction.rs at line 229
self.payee = Default::default();self.payee = None; - replacement in common/beancount-types/src/transaction.rs at line 262
pub fn set_metadata(&mut self, metadata: impl Into<TransactionMetadata>) -> &mut Self {self.metadata = metadata.into();pub fn set_meta(&mut self, meta: impl Into<MetadataMap>) -> &mut Self {self.meta = meta.into(); - edit in common/beancount-types/src/transaction.rs at line 284
} - replacement in common/beancount-types/src/transaction.rs at line 286
#[inline]pub fn with_metadata(&mut self, block: impl FnOnce(&mut TransactionMetadata)) -> &mut Self {block(&mut self.metadata);selfimpl Transaction {pub fn main_account(&self) -> Option<&Acc> {self.postings.first().map(|posting| posting.account.as_ref()) - edit in common/beancount-types/src/transaction.rs at line 294
pub fn with_postings(&mut self, block: impl FnOnce(&mut Vec<Posting>)) -> &mut Self {block(&mut self.postings);self}}impl Transaction {#[inline] - replacement in common/beancount-types/src/transaction.rs at line 295
self.metadata.key_valueself.meta - replacement in common/beancount-types/src/transaction.rs at line 308
metadata,links,meta, - replacement in common/beancount-types/src/transaction.rs at line 323
write!(f, "{metadata}")?;for link in links {write!(f, "\n {link}")?;}for (key, value) in meta {write!(f, "\n {key}: {value}")?;} - file addition: price.rs[6.44]
use core::fmt::Display;use time::Date;use crate::Amount;use crate::Commodity;use crate::MetadataKey;use crate::MetadataMap;use crate::MetadataValue;#[derive(Clone, Debug, Eq, Hash, PartialEq)]pub struct Price {pub date: Date,pub quote: Commodity,pub price: Amount,pub meta: MetadataMap,}impl Price {pub fn new(date: Date, quote: Commodity, price: Amount) -> Self {let meta = MetadataMap::default();Self {date,quote,price,meta,}}}impl Price {#[inline]pub fn add_meta(&mut self,key: impl Into<MetadataKey>,value: impl Into<MetadataValue>,) -> &mut Self {self.meta.insert(key.into(), value.into());self}#[inline]pub fn clear_meta(&mut self) -> &mut Self {self.meta.clear();self}#[inline]pub fn set_quote(&mut self, quote: impl Into<Commodity>) -> &mut Self {self.quote = quote.into();self}#[inline]pub fn set_price(&mut self, price: Amount) -> &mut Self {self.price = price;self}#[inline]pub fn set_date(&mut self, date: Date) -> &mut Self {self.date = date;self}#[inline]pub fn set_meta(&mut self, meta: impl Into<MetadataMap>) -> &mut Self {self.meta = meta.into();self}}impl Display for Price {fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {let Self {date,quote,price,meta,} = self;write!(f, "{date} price {quote} {price}")?;for (key, value) in meta {write!(f, "\n {key}: {value}")?;}Ok(())}} - replacement in common/beancount-types/src/metadata.rs at line 1[6.2624]→[6.2625:2982](∅→∅),[6.2982]→[6.381:572](∅→∅),[6.572]→[6.2982:6532](∅→∅),[6.2982]→[6.2982:6532](∅→∅),[6.6532]→[6.573:714](∅→∅),[6.714]→[6.6557:6691](∅→∅),[6.6557]→[6.6557:6691](∅→∅),[6.6691]→[6.715:839](∅→∅),[6.839]→[6.6691:7247](∅→∅),[6.6691]→[6.6691:7247](∅→∅)
use core::borrow::Borrow;use core::fmt::Display;use core::ops::Deref;use core::str::FromStr;use alloc::collections::BTreeMap;use delegate::delegate;use miette::Diagnostic;use snafu::ensure;use snafu::Backtrace;use snafu::Snafu;#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]#[repr(transparent)]pub struct Key {name: String,}impl Key {pub const unsafe fn from_unchecked(name: String) -> Self {Self { name }}}impl Borrow<str> for Key {fn borrow(&self) -> &str {&self.name}}impl Display for Key {fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {f.write_str(&self.name)}}impl FromStr for Key {type Err = KeyError;#[inline]fn from_str(name: &str) -> Result<Self, Self::Err> {ensure!(is_valid_key(name), KeySnafu { name });let name = name.to_owned();Ok(Self { name })}}impl TryFrom<String> for Key {type Error = KeyError;fn try_from(name: String) -> Result<Self, Self::Error> {ensure!(is_valid_key(&name), KeySnafu { name });Ok(Self { name })}}#[derive(Debug, Diagnostic, Snafu)]pub struct KeyError {backtrace: Backtrace,name: String,}#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]#[repr(transparent)]pub struct Link {name: String,}impl Borrow<Lnk> for Link {fn borrow(&self) -> &Lnk {self}}impl Deref for Link {type Target = Lnk;fn deref(&self) -> &Self::Target {#[allow(unsafe_code)]unsafe {// SAFETY: self.name is a valid link name, by constructionSelf::Target::from_unchecked(&self.name)}}}impl Display for Link {delegate! {to self.name {fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result;}}}impl From<&Lnk> for Link {#[inline]fn from(link: &Lnk) -> Self {link.to_owned()}}impl FromStr for Link {type Err = LinkError;#[inline]fn from_str(name: &str) -> Result<Self, Self::Err> {<&Lnk>::try_from(name).map(Self::from)}}impl TryFrom<String> for Link {type Error = LinkError;#[inline]fn try_from(name: String) -> Result<Self, Self::Error> {ensure!(is_valid_link_name(&name), LinkSnafu { name });Ok(Self { name })}}#[derive(Debug, Diagnostic, Snafu)]pub struct LinkError {name: String,backtrace: Backtrace,}#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]#[repr(transparent)]pub struct Lnk {name: str,}impl Lnk {#[allow(unsafe_code)]#[inline]const unsafe fn from_unchecked(name: &str) -> &Self {let name: *const _ = name;let name = name as *const _;unsafe { &*name }}}impl ToOwned for Lnk {type Owned = Link;#[inline]fn to_owned(&self) -> Self::Owned {let name = self.name.to_owned();Self::Owned { name }}}impl<'l> TryFrom<&'l str> for &'l Lnk {type Error = LinkError;#[inline]fn try_from(name: &'l str) -> Result<Self, Self::Error> {ensure!(is_valid_link_name(name), LinkSnafu { name });Ok(#[allow(unsafe_code)]unsafe {// SAFETY: we have ensured that `name` is a valid link.Lnk::from_unchecked(name)},)}}#[derive(Clone, Debug, Default, Eq, Hash, PartialEq)]pub struct Transaction {pub key_value: BTreeMap<Key, Value>,pub links: Vec<Link>,}impl Transaction {#[inline]pub fn add_link(&mut self, link: impl Into<Link>) -> &mut Self {self.links.push(link.into());self}#[inline]pub fn add_key_value(&mut self, key: impl Into<Key>, value: impl Into<Value>) -> &mut Self {self.key_value.insert(key.into(), value.into());self}}impl Display for Transaction {fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {for link in &self.links {write!(f, "\n {link}")?;}for (key, value) in &self.key_value {write!(f, "\n {key}: {value}")?;}Ok(())}}#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]pub enum Value {String(String),}impl Value {pub fn as_str(&self) -> Option<&str> {let Self::String(inner) = self;Some(inner)}}impl Display for Value {fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {match self {Value::String(inner) => write!(f, "{inner:?}"),}}}impl<S> From<S> for ValuewhereS: Into<String>,{fn from(value: S) -> Self {Self::String(value.into())}}fn is_valid_key(name: &str) -> bool {lazy_regex::regex_is_match!(r"^(:?[a-z][a-zA-Z0-9\-_]+)$", name)}fn is_valid_link_name(name: &str) -> bool {lazy_regex::regex_is_match!(r"^(:?\^[A-Za-z0-9\-_/.]+)$", name)}[6.2624]pub mod kv;pub mod link; - file addition: metadata[6.44]
- file addition: link.rs[0.1851]
use alloc::collections::BTreeSet;use delegate::delegate;use miette::Diagnostic;use snafu::Backtrace;use snafu::ensure;use snafu::Snafu;use core::str::FromStr;use core::fmt::Display;use core::ops::Deref;use core::borrow::Borrow;#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]#[repr(transparent)]pub struct Link {pub(crate) name: String,}impl Borrow<Lnk> for Link {fn borrow(&self) -> &Lnk {self}}impl Deref for Link {type Target = Lnk;fn deref(&self) -> &Self::Target {#[allow(unsafe_code)]unsafe {// SAFETY: self.name is a valid link name, by constructionSelf::Target::from_unchecked(&self.name)}}}impl Display for Link {delegate! {to self.name {fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result;}}}impl From<&Lnk> for Link {#[inline]fn from(link: &Lnk) -> Self {link.to_owned()}}impl FromStr for Link {type Err = LinkError;#[inline]fn from_str(name: &str) -> Result<Self, Self::Err> {<&Lnk>::try_from(name).map(Self::from)}}impl TryFrom<String> for Link {type Error = LinkError;#[inline]fn try_from(name: String) -> Result<Self, Self::Error> {ensure!(is_valid_link_name(&name), LinkSnafu { name });Ok(Self { name })}}#[derive(Debug, Diagnostic, Snafu)]pub struct LinkError {pub(crate) name: String,pub(crate) backtrace: Backtrace,}#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]#[repr(transparent)]pub struct Lnk {pub(crate) name: str,}impl Lnk {#[allow(unsafe_code)]#[inline]pub(crate) const unsafe fn from_unchecked(name: &str) -> &Self {let name: *const _ = name;let name = name as *const _;unsafe { &*name }}}impl ToOwned for Lnk {type Owned = Link;#[inline]fn to_owned(&self) -> Self::Owned {let name = self.name.to_owned();Self::Owned { name }}}impl<'l> TryFrom<&'l str> for &'l Lnk {type Error = LinkError;#[inline]fn try_from(name: &'l str) -> Result<Self, Self::Error> {ensure!(is_valid_link_name(name), LinkSnafu { name });Ok(#[allow(unsafe_code)]unsafe {// SAFETY: we have ensured that `name` is a valid link.Lnk::from_unchecked(name)},)}}pub type Set = BTreeSet<Link>;fn is_valid_link_name(name: &str) -> bool {lazy_regex::regex_is_match!(r"^(:?\^[A-Za-z0-9\-_/.]+)$", name)} - file addition: kv.rs[0.1851]
use alloc::collections::BTreeMap;use miette::Diagnostic;use rust_decimal::Decimal;use snafu::Backtrace;use snafu::ensure;use snafu::Snafu;use core::ops::Deref;use core::str::FromStr;use core::fmt::Display;use core::borrow::Borrow;pub mod common_keys;#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]#[repr(transparent)]pub struct Key {name: String,}impl Key {#[must_use]pub const unsafe fn from_unchecked(name: String) -> Self {Self { name }}}impl Borrow<Ky> for Key {fn borrow(&self) -> &Ky {self}}impl Borrow<str> for Key {fn borrow(&self) -> &str {&self.name}}impl Deref for Key {type Target = Ky;fn deref(&self) -> &Self::Target {unsafe { Ky::from_unchecked(&self.name) }}}impl Display for Key {fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {f.write_str(&self.name)}}impl From<&Ky> for Key {fn from(value: &Ky) -> Self {value.to_owned()}}impl FromStr for Key {type Err = KeyError;#[inline]fn from_str(name: &str) -> Result<Self, Self::Err> {Self::try_from(name)}}impl TryFrom<&str> for Key {type Error = KeyError;#[inline]fn try_from(name: &str) -> Result<Self, Self::Error> {ensure!(is_valid_key(name), KeySnafu { name });let name = name.to_owned();Ok(Self { name })}}impl TryFrom<String> for Key {type Error = KeyError;#[inline]fn try_from(name: String) -> Result<Self, Self::Error> {ensure!(is_valid_key(&name), KeySnafu { name });Ok(Self { name })}}#[derive(Debug, Diagnostic, Snafu)]pub struct KeyError {pub(crate) backtrace: Backtrace,pub(crate) name: String,}#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]#[repr(transparent)]pub struct Ky {name: str,}impl Ky {#[must_use]pub const unsafe fn from_unchecked(name: &str) -> &Self {unsafe {let name: *const _ = name;let name: *const Self = name as _;&*name}}}impl Borrow<str> for Ky {fn borrow(&self) -> &str {&self.name}}impl Display for Ky {fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {f.write_str(&self.name)}}impl ToOwned for Ky {type Owned = Key;fn to_owned(&self) -> Self::Owned {let name = self.name.to_owned();Key { name }}}impl<'s> TryFrom<&'s str> for &'s Ky {type Error = KeyError;#[inline]fn try_from(name: &'s str) -> Result<Self, Self::Error> {ensure!(is_valid_key(name), KeySnafu { name });Ok(unsafe { Ky::from_unchecked(name) })}}pub type Map = BTreeMap<Key, Value>;#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]pub enum Value {Number(Decimal),String(String),}impl Value {#[must_use]pub fn as_number(&self) -> Option<Decimal> {if let Self::Number(v) = self {Some(*v)} else {None}}#[must_use]pub fn as_str(&self) -> Option<&str> {if let Self::String(inner) = self {Some(inner)} else {None}}}impl Display for Value {fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {match self {Value::Number(inner) => inner.fmt(f),Value::String(inner) => write!(f, "{inner:?}"),}}}impl From<&str> for Value {fn from(value: &str) -> Self {Self::from(value.to_owned())}}impl From<Decimal> for Value {fn from(value: Decimal) -> Self {Self::Number(value)}}impl From<String> for Value {fn from(value: String) -> Self {Self::String(value)}}impl From<u8> for Value {fn from(value: u8) -> Self {Self::Number(Decimal::from(value))}}impl From<u16> for Value {fn from(value: u16) -> Self {Self::Number(Decimal::from(value))}}impl From<u32> for Value {fn from(value: u32) -> Self {Self::Number(Decimal::from(value))}}impl From<u64> for Value {fn from(value: u64) -> Self {Self::Number(Decimal::from(value))}}fn is_valid_key(name: &str) -> bool {lazy_regex::regex_is_match!(r"^(:?[a-z][a-zA-Z0-9\-_]+)$", name)} - file addition: kv[0.1851]
- file addition: common_keys.rs[0.9034]
use crate::MetadataKy;pub const FILENAME: &MetadataKy = unsafe { MetadataKy::from_unchecked("filename") };pub const LINE_NUMBER: &MetadataKy = unsafe { MetadataKy::from_unchecked("lineno") };pub const TIMESTAMP: &MetadataKy = unsafe { MetadataKy::from_unchecked("timestamp") };pub const TRANSACTION_ID: &MetadataKy = unsafe { MetadataKy::from_unchecked("transaction-id") }; - replacement in common/beancount-types/src/lib.rs at line 14
pub use crate::metadata::Key as MetadataKey;pub use crate::metadata::Link;pub use crate::metadata::Transaction as TransactionMetadata;pub use crate::metadata::Value as MetadataValue;pub use crate::metadata::kv::common_keys;pub use crate::metadata::kv::Key as MetadataKey;pub use crate::metadata::kv::Ky as MetadataKy;pub use crate::metadata::kv::Map as MetadataMap;pub use crate::metadata::kv::Value as MetadataValue;pub use crate::metadata::link::Link;pub use crate::metadata::link::Set as LinkSet; - edit in common/beancount-types/src/lib.rs at line 47
}impl Directive {pub fn add_meta(&mut self,key: impl Into<MetadataKey>,value: impl Into<MetadataValue>,) -> &mut Self {match self {Directive::Balance(inner) => {inner.add_meta(key, value);}Directive::Price(inner) => {inner.add_meta(key, value);}Directive::Transaction(inner) => {inner.add_meta(key, value);}}self} - edit in common/beancount-types/src/lib.rs at line 72
/// Returns `true` if the directive is [`Balance`].////// [`Balance`]: Directive::Balance#[must_use]pub fn is_balance(&self) -> bool {matches!(self, Self::Balance(..))}}impl Directive { - replacement in common/beancount-types/src/lib.rs at line 94
Directive::Transaction(transaction) => transaction.postings.get(0).map(|posting| posting.account.as_ref()),Directive::Transaction(transaction) => transaction.main_account(), - edit in common/beancount-types/src/lib.rs at line 123
impl From<Price> for Directive {fn from(price: Price) -> Self {Self::Price(price)}} - edit in common/beancount-types/src/balance.rs at line 10
use crate::MetadataKey;use crate::MetadataMap;use crate::MetadataValue; - replacement in common/beancount-types/src/balance.rs at line 14
#[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd)]#[derive(Clone, Debug, Eq, Hash, PartialEq)] - edit in common/beancount-types/src/balance.rs at line 21
pub meta: MetadataMap,}impl Balance {pub fn new(date: Date, account: impl Into<Account>, amount: Amount) -> Self {let (account, meta) = (account.into(), MetadataMap::default());Self {date,account,amount,meta,}} - edit in common/beancount-types/src/balance.rs at line 38
#[inline]pub fn add_meta(&mut self,key: impl Into<MetadataKey>,value: impl Into<MetadataValue>,) -> &mut Self {self.meta.insert(key.into(), value.into());self} - edit in common/beancount-types/src/balance.rs at line 49
pub fn clear_meta(&mut self) -> &mut Self {self.meta.clear();self}#[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 = amount;self}#[inline]pub fn set_date(&mut self, date: Date) -> &mut Self {self.date = date;self}#[inline]pub fn set_meta(&mut self, meta: impl Into<MetadataMap>) -> &mut Self {self.meta = meta.into();self}}impl Balance {#[inline]#[must_use] - edit in common/beancount-types/src/balance.rs at line 97
meta, - replacement in common/beancount-types/src/balance.rs at line 99
write!(f, "{date} balance {account} {amount}")write!(f, "{date} balance {account} {amount}")?;for (key, value) in meta {write!(f, "\n {key}: {value}")?;}Ok(()) - edit in common/beancount-types/src/account/template.rs at line 13
use crate::Acc; - edit in common/beancount-types/src/account/template.rs at line 113
pub fn base(&self) -> &Acc {&self.base} - replacement in common/beancount-tree-writer/src/lib.rs at line 11
use beancount_types::Account;use beancount_types::Acc;use beancount_types::Balance;use beancount_types::Commodity; - edit in common/beancount-tree-writer/src/lib.rs at line 15
use beancount_types::Price; - replacement in common/beancount-tree-writer/src/lib.rs at line 26
use time::Month;use time::Date;use tracing::warn; - replacement in common/beancount-tree-writer/src/lib.rs at line 61
.into_group_map_by(|directive| DirectiveIndex::try_from(directive).unwrap());.filter_map(|directive| {Some((file_for(&self.config.output_path, &directive)?, directive))}).into_group_map(); - replacement in common/beancount-tree-writer/src/lib.rs at line 68
.map(|(index, directives)| self.write_month(pretty_printer_config, index, directives)).map(|(file, directives)| self.write_month(pretty_printer_config, &file, directives)) - replacement in common/beancount-tree-writer/src/lib.rs at line 84
index: DirectiveIndex,file: &Utf8Path, - replacement in common/beancount-tree-writer/src/lib.rs at line 98
let file = index.file_in(&self.config.output_path);self.open_file(&file)self.open_file(file) - replacement in common/beancount-tree-writer/src/lib.rs at line 102
.context(PrettyPrintingSnafu { file, index }).context(PrettyPrintingSnafu { file }) - replacement in common/beancount-tree-writer/src/lib.rs at line 116
#[derive(Debug, Eq, Hash, PartialEq)]struct DirectiveIndex {account: Account,year: i32,month: Month,fn file_for(base: &Utf8Path, directive: &Directive) -> Option<Utf8PathBuf> {match directive {Directive::Balance(Balance { date, account, .. }) => {Some(account_file(base, account, *date))}Directive::Price(Price { quote, .. }) => Some(price_file(base, quote)),Directive::Transaction(transaction) => {if let Some(account) = transaction.main_account() {Some(account_file(base, account, transaction.date))} else {warn!(?transaction,"ignoring transaction since it has no postings");None}}} - replacement in common/beancount-tree-writer/src/lib.rs at line 139
impl DirectiveIndex {fn file_in(&self, path: &Utf8Path) -> Utf8PathBuf {let Self {account,year,month,} = self;let month = *month as u8;fn account_file(base: &Utf8Path, account: &Acc, date: Date) -> Utf8PathBuf {let year = date.year();let month = date.month();let month = month as u8; - replacement in common/beancount-tree-writer/src/lib.rs at line 144
let separator = path::MAIN_SEPARATOR;let separator = path::MAIN_SEPARATOR; - replacement in common/beancount-tree-writer/src/lib.rs at line 146[6.371]→[6.3383:3424](∅→∅),[6.3383]→[6.3383:3424](∅→∅),[6.3424]→[6.372:490](∅→∅),[6.490]→[6.3565:3599](∅→∅),[6.3565]→[6.3565:3599](∅→∅)
let mut path = path.to_string();let additional = account.len() + 4 + 2 + 5 + 3; // account name + year + month + extension + extra separatorspath.reserve(additional);let mut path = base.to_string();let additional = account.len() + 4 + 2 + 5 + 3; // account name + year + month + extension + extra separatorspath.reserve(additional); - replacement in common/beancount-tree-writer/src/lib.rs at line 150
account.segments().for_each(|segment| write!(path, "{separator}{segment}").unwrap());account.segments().for_each(|segment| write!(path, "{separator}{segment}").unwrap()); - replacement in common/beancount-tree-writer/src/lib.rs at line 154
write!(path, "{separator}{year}{separator}{month:02}.bean").unwrap();write!(path, "{separator}{year}{separator}{month:02}.bean").unwrap(); - replacement in common/beancount-tree-writer/src/lib.rs at line 156
path.into()}Utf8PathBuf::from(path) - edit in common/beancount-tree-writer/src/lib.rs at line 158
impl TryFrom<&Directive> for DirectiveIndex {type Error = ErrorKind; - replacement in common/beancount-tree-writer/src/lib.rs at line 159
fn try_from(value: &Directive) -> Result<Self, Self::Error> {let account = if let Some(account) = value.main_account() {account.to_owned()} else {return IndexingDirectiveSnafu {directive: value.clone(),}.fail();};let date = value.date();let year = date.year();let month = date.month();fn price_file(base: &Utf8Path, quote: &Commodity) -> Utf8PathBuf {let mut path = base.join("prices");path.push(&**quote);path.set_extension("bean"); - replacement in common/beancount-tree-writer/src/lib.rs at line 164
Ok(Self {account,year,month,})}path - replacement in common/beancount-tree-writer/src/lib.rs at line 175
#[snafu(display("error while pretty printing directives for key {index:?} to {file}"))]#[snafu(display("error while pretty printing directives to {file}"))] - edit in common/beancount-tree-writer/src/lib.rs at line 179
index: DirectiveIndex, - edit in common/beancount-tree-writer/Cargo.toml at line 26[21.766]
tracing.workspace = true - edit in common/beancount-pretty-printer/src/lib.rs at line 13
use beancount_types::TransactionMetadata; - edit in common/beancount-pretty-printer/src/lib.rs at line 157
meta, - replacement in common/beancount-pretty-printer/src/lib.rs at line 161
self.print_amount(self.config.amount, amount)self.print_amount(self.config.amount, amount)?;for (key, value) in meta {write!(self.inner, "\n {key}: {value}")?;}Ok(()) - replacement in common/beancount-pretty-printer/src/lib.rs at line 207
metadata,links,meta, - replacement in common/beancount-pretty-printer/src/lib.rs at line 215
(Some(payee), Some(narration)) => write!(self.inner, r#" "{payee}" "{narration}""#)?,(Some(payee), None) => write!(self.inner, r#" "{payee}" """#)?,(None, Some(narration)) => write!(self.inner, r#" "{narration}""#)?,(Some(payee), Some(narration)) => write!(self.inner, r" {payee:?} {narration:?}")?,(Some(payee), None) => write!(self.inner, r#" {payee:?} """#)?,(None, Some(narration)) => write!(self.inner, r" {narration:?}")?, - replacement in common/beancount-pretty-printer/src/lib.rs at line 221
self.print_transaction_metadata(metadata)?;for link in links {write!(self.inner, "\n {link}")?;}for (key, value) in meta {write!(self.inner, "\n {key}: {value}")?;} - edit in common/beancount-pretty-printer/src/lib.rs at line 259
fn print_transaction_metadata(&mut self, metadata: &TransactionMetadata) -> Result<()> {let TransactionMetadata {key_value, links, ..} = metadata;for link in links {write!(self.inner, "\n {link}")?;}for (key, value) in key_value {write!(self.inner, "\n {key}: {value}")?;}Ok(())}