1 unstable release
0.2.2 | Feb 1, 2025 |
---|
#10 in #monthly
140 downloads per month
Used in 12 crates
(4 directly)
160KB
2.5K
SLoC
README.md
tktax-monthly
A Rust library for monthly financial transaction aggregation, designed to integrate seamlessly with the tktax
ecosystem. This crate provides abstractions for enumerating, aggregating, and displaying monthly transactions, allowing concise transformations of raw data into validated summaries. By leveraging AvgMonthly and MonthlySummary structures, users gain production-ready tools suitable for rigorous accounting and tax-reporting applications.
Overview
-
AvgMonthly<TxCat>:
A structure for representing the average monetary outlay or inflow within a givenTransactionCategory
. It encapsulates:ty
- TheTransactionType
(e.g., credit, debit).category
- The domain-specific transaction category.value
- The calculated averageMonetaryAmount
.
-
MonthlySummary:
A chronological consolidation of transactions starting atstart_date
. Each field accumulates tallies (akin to aggregare in Latin) of different transaction types:credits
debits
checks
deposits
point_of_sale
These monoidal accumulations resemble the ἐμπορική συναλλαγή (commercial transaction) grouping, keeping numeric precision intact via MonetaryAmount
.
- CreateMonthlySummary:
A trait that can be implemented by a higher-level data repository to produce a collection ofMonthlySummary
instances.
Usage Example
use tktax_monthly::{CreateMonthlySummary, MonthlySummary};
fn compute_monthly_summaries(repo: &impl CreateMonthlySummary) {
let summaries: Vec<MonthlySummary> = repo.monthly_summary();
for summary in summaries {
println!("{:#?}", summary);
// Implement domain logic here:
// e.g., sending this summary for further auditing or analytics
}
}
- Add the dependency to your
Cargo.toml
:[dependencies] tktax-monthly = "0.1.0"
- Implement
CreateMonthlySummary
in your repository type, ensuring it returns a vector ofMonthlySummary
objects. - Generate monthly summaries, optionally using
AvgMonthly
for category-based average calculations.
Features
- Robust Aggregation: Safely accumulates monetary transactions across multiple categories.
- Human-Readable Debugging: The custom
fmt::Debug
allows single-line or pretty-printed views. - Typed Categories: Avoids stringly-typed design through domain-centric enumerations.
- Production-Ready: Zero usage of
.unwrap()
or.expect()
, ensuring stable error handling paths.
For additional documentation and usage details, consult the repository or open an issue for feature requests.
Dependencies
~26–37MB
~640K SLoC