tktax-budgeting
tktax-budgeting is a Rust library in the tktax ecosystem providing structures and traits for budget management and transaction category comparisons. It enables users to:
- Define budgets on monthly, quarterly, or annual time horizons.
- Compare actual expenditures or credits to budgeted amounts per category.
- Employ strongly-typed domain models with robust error handling (no stringly-typed errors).
Features
-
Budget<TxCat>- Stores monthly category amounts and default allocations.
- Built using
derive_builder, allowing for flexible initialization. - Methods for dynamically setting or removing category budgets without re-instantiation.
-
BudgetComparison<TxCat>- Summarizes per-category actual vs. budgeted values, including a variance measurement.
-
Budgeting<TxCat>Trait- Facilitates budget-to-actual comparisons for a domain
Account. - Offers both per-month and aggregate-based comparison methods.
- Facilitates budget-to-actual comparisons for a domain
-
Time Period Abstractions
BudgetTimePeriodenumerates supported intervals (Monthly, Quarterly, Annual).
-
Error Handling
BudgetErrorcovers domain-specific error conditions without resorting to textual messages.
Usage
Add the following to your Cargo.toml:
[]
= "0.1.0"
Example
use ;
use Account;
use MonetaryAmount;
use TransactionCategory;
use HashMap;
// Custom transaction category for illustration:
// Implement the TransactionCategory trait:
// Construct a budget:
let mut monthly_budgets = new;
monthly_budgets.insert;
monthly_budgets.insert;
monthly_budgets.insert;
let budget = default
.monthly_category_budgets
.default_monthly_budget
.time_period
.build
.map_err?;
// Suppose we already have an Account populated with transactions:
let my_account = empty; // your domain logic populates it
// We also have a category map, or a function to map transactions to MyCategory:
let category_map = /* your domain CategoryMap<MyCategory> */;
// Compare actual amounts to budget:
let comps = my_account.compare_actual_to_budget_monthly;
for comparison in comps
Testing
The library contains a suite of unit tests demonstrating the usage patterns:
- Verifying the
Budgetbuilder defaults and field assignments. - Checking dynamic category budget addition and removal.
- Confirming correct computation of variances.
To run tests:
Contributing
Contributions or issues can be reported at the project repository.
License
This project is licensed under the MIT license.