tktax-amazon
High-performance crate for deserializing Amazon CSV exports, unifying multi-epoch transaction data, and generating tabular outputs for taxation workflows. Provides idiomatic Rust abstractions for Amazon transactions, macros to instantiate medical/business purchases, and configurable options to merge distinct CSV epochs into consolidated records.
Overview
-
CSV Parsing (Latin: comma separata tabula):
parse_amazon_csvaccepts in-memory byte buffers and deserializes them into strongly-typed Rust structures implementing theAmazonTxntrait.- Resilient to flexible CSV terminators, embedded quotes, and partial escaping sequences.
-
Transaction Fusion (Greek: συναρμολόγηση):
fuse_amazon_transactions_from_two_epochsmerges distinct epochs (e.g., AmazonTx1 vs. AmazonTx2) into a uniformAmazonTxvector.- Simplifies archival or further analytic workflows.
-
Configurable CSV Aggregation:
maybe_fuse_amazon_csv_from_two_epochsdemonstrates orchestrating both epochs’ CSV data into a single CSV output, contingent upon a user-suppliedAmazonConfig.
-
Macros for Medical/Business Purchases:
amazon_medical!&amazon_business!reduce boilerplate when constructing domain-specific line items, integrating cost, quantity, and date fields into robust builder patterns.
-
Auxiliary Constructs:
AmazonItemListingandAmazonItemMapfacilitate indexing or referencing items by known identifiers.IndexedAmazonTxensures each record includes a short symbolic code plus standard transaction metadata.
-
Error Handling:
- Implements
AmazonError(IoError,CsvError, andChronoParseError) to capture explicit runtime anomalies. - Encourages safe error propagation without unwinding the runtime or resorting to stringly-typed errors.
- Implements
Usage
Parsing and Fusing CSVs:
use ;
On-the-Fly Example Items:
use NaiveDate;
use amazon_medical;
use Decimal;
// Construct a one-off medical purchase
let med_purchase = amazon_medical!;
println!;
Configuration-Based Fusion:
let config = AmazonConfig ;
match maybe_fuse_amazon_csv_from_two_epochs
Features and Extensions
- Multi-Epoch Compatibility: Automatic unification of different Amazon CSV layouts.
- Macro-Based Builders: Streamlined creation of typed domain items for specialized expenses.
- Decoupled Category Logic:
LineItem<TxCat>trait obtains a user-defined category enumeration for accounting segregation. - Chrono & Decimal Integration: Leverages
NaiveDatefor time fields,Decimalfor quantity, and customMonetaryAmountfor robust currency handling.
License
Distributed under the MIT License.