1 unstable release
0.2.2 | Feb 1, 2025 |
---|
#3 in #tktax
122 downloads per month
Used in tktax
175KB
2.5K
SLoC
tktax-year-comparison
tktax-year-comparison is a Rust crate focused on performing comparative accounting between multiple fiscal years for the TKTAX ecosystem. It provides tools to compute cross-year differentials and construct multi-year summaries. This library is especially helpful for uncovering changes in total monetary amounts and extracting year-by-year data across diverse sets of transactions.
Features
-
Differential Analysis
- Compare totals between two distinct
Account
instances. - Obtain a
YearComparison
struct containing each year’s identifier and the total difference in amounts.
- Compare totals between two distinct
-
Multi-Year Aggregation
- Consolidate data across any number of
Account
s. - Produce a
MultiYearSummary
that maps eachTrackedYear
to a summedMonetaryAmount
. - Facilitates high-level audits of various yearly totals.
- Consolidate data across any number of
-
Extensibility
- Straightforward to integrate additional fields or metrics (e.g., totals of certain transaction types).
- Built to interoperate with other TKTAX libraries, such as
tktax_money
andtktax_transaction
.
Usage Example
Below is a minimal code sample illustrating how to compare two years and then aggregate a set of Account
s:
use tktax_year_comparison::{
DifferentialAnalysis,
aggregate_multi_year,
YearComparison,
MultiYearSummary,
};
// Suppose we have two `Account` instances from different years: `acct_2021` and `acct_2022`.
// Both satisfy `DifferentialAnalysis` from this crate.
if let Some(diff) = acct_2021.compare_years(&acct_2022) {
println!("Year A: {:?}", diff.year_a);
println!("Year B: {:?}", diff.year_b);
println!("Difference: {:?}", diff.total_difference);
} else {
println!("Unable to perform cross-year comparison.");
}
// To aggregate a slice of `Account`s spanning different years:
let accounts = vec![acct_2021, acct_2022, /* possibly more */];
let summary = aggregate_multi_year(&accounts);
for (year, total) in &summary.yearly_totals {
println!("Year: {:?}, Summed Amount: {:?}", year, total);
}
Data Structures
-
YearComparison
- Tracks the two compared years (year_a
andyear_b
).
- Stores thetotal_difference
(year_b - year_a
). -
MultiYearSummary
- Maintains aHashMap<TrackedYear, MonetaryAmount>
, mapping eachTrackedYear
to its aggregated total.
Crate Integration
To incorporate tktax-year-comparison into your project, add it to your Cargo.toml
:
[dependencies]
tktax-year-comparison = "0.1"
Then import it in your Rust code:
use tktax_year_comparison::*;
License
Licensed under either of
- Apache License, Version 2.0,
- MIT license
at your option.
For advanced or specialized usage (e.g., computing nuanced debits/credits breakdowns), consider extending YearComparison
or MultiYearSummary
. Their internal fields remain amenable to expansions to capture more thorough financial data (Latin: data pecuniaria, Greek: δεδομένα λογιστικά).
Contributions and feedback welcome via the project repository.
Dependencies
~28–38MB
~648K SLoC