| Crates.io | tktax-budgeting |
| lib.rs | tktax-budgeting |
| version | 0.2.2 |
| created_at | 2025-02-01 16:26:36.827701+00 |
| updated_at | 2025-02-01 16:26:36.827701+00 |
| description | Budget planning and comparison utilities for tktax-based financial applications. |
| homepage | |
| repository | https://github.com/klebs6/tktax |
| max_upload_size | |
| id | 1538558 |
| size | 94,977 |
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:
Budget<TxCat>
derive_builder, allowing for flexible initialization.BudgetComparison<TxCat>
Budgeting<TxCat> Trait
Account.Time Period Abstractions
BudgetTimePeriod enumerates supported intervals (Monthly, Quarterly, Annual).Error Handling
BudgetError covers domain-specific error conditions without resorting to textual messages.Add the following to your Cargo.toml:
[dependencies]
tktax-budgeting = "0.1.0"
use tktax_budgeting::{
BudgetBuilder, Budget, Budgeting, BudgetTimePeriod,
BudgetComparison, BudgetError,
};
use tktax_account::Account;
use tktax_money::MonetaryAmount;
use tktax_transaction_category::TransactionCategory;
use std::collections::HashMap;
// Custom transaction category for illustration:
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
enum MyCategory {
Dining,
Groceries,
Rent,
}
// Implement the TransactionCategory trait:
impl TransactionCategory for MyCategory {}
// Construct a budget:
let mut monthly_budgets = HashMap::new();
monthly_budgets.insert(MyCategory::Dining, MonetaryAmount::from(200));
monthly_budgets.insert(MyCategory::Groceries, MonetaryAmount::from(300));
monthly_budgets.insert(MyCategory::Rent, MonetaryAmount::from(800));
let budget = BudgetBuilder::<MyCategory>::default()
.monthly_category_budgets(monthly_budgets)
.default_monthly_budget(MonetaryAmount::from(50))
.time_period(BudgetTimePeriod::Monthly)
.build()
.map_err(|_| BudgetError::IncompleteBuilder)?;
// Suppose we already have an Account populated with transactions:
let my_account = 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(&budget, &category_map);
for comparison in comps {
println!(
"Category: {:?}, Budgeted: {}, Actual: {}, Variance: {}",
comparison.category(),
comparison.budgeted(),
comparison.actual(),
comparison.variance()
);
}
The library contains a suite of unit tests demonstrating the usage patterns:
Budget builder defaults and field assignments.To run tests:
cargo test
Contributions or issues can be reported at the project repository.
This project is licensed under the MIT license.