| Crates.io | tktax-line-item |
| lib.rs | tktax-line-item |
| version | 0.2.2 |
| created_at | 2025-02-01 02:26:52.852088+00 |
| updated_at | 2025-02-01 02:26:52.852088+00 |
| description | Provides a trait and associated functionality for transaction line items in the TKTAX ecosystem. |
| homepage | |
| repository | https://github.com/klebs6/tktax |
| max_upload_size | |
| id | 1538012 |
| size | 80,548 |
The tktax-line-item crate defines a LineItem trait for describing individual transaction-based entries within the broader TKTAX ecosystem. It integrates with the following companion crates:
Its core functionality enables modeling of financial line items with precise quantity, pricing, tax category, and transaction references.
The primary component is:
pub trait LineItem<TxCat: TransactionCategory + 'static>: Debug {
/// Provides the quantity of this line item.
fn quantity(&self) -> Decimal;
/// Provides the price of this line item as a monetary amount.
fn price(&self) -> MonetaryAmount;
/// Provides the category of this line item, e.g., tax or accounting classification.
fn category(&self) -> TxCat;
/// Computes the total transaction amount for this item (e.g., quantity * price).
fn tx_amount(&self) -> MonetaryAmount;
/// Returns an optional reference to the underlying transaction.
fn tx(&self) -> Option<&Transaction>;
/// Identifies the tag to associate with this line item.
fn tag() -> &'static str;
}
This trait allows each implementing type to define relevant financial or tax-oriented fields while maintaining a consistent interface. The generic parameter <TxCat> is any type implementing TransactionCategory with static lifetime constraints.
To use tktax-line-item in your Cargo project, add the following to your Cargo.toml:
[dependencies]
tktax-line-item = "0.1"
Then import and implement the trait:
use tktax_line_item::LineItem;
use tktax_transaction_category::TransactionCategory;
use tktax_money::{Decimal, MonetaryAmount};
use tktax_transaction::Transaction;
#[derive(Debug)]
struct ExampleCategory; // Suppose this implements TransactionCategory
#[derive(Debug)]
struct ExampleLineItem {
// Provide any domain-specific fields as needed
}
impl TransactionCategory for ExampleCategory {
fn identifier(&self) -> &str {
"EXAMPLE_CATEGORY"
}
// ...additional required methods...
}
impl LineItem<ExampleCategory> for ExampleLineItem {
fn quantity(&self) -> Decimal {
// ...
}
fn price(&self) -> MonetaryAmount {
// ...
}
fn category(&self) -> ExampleCategory {
ExampleCategory
}
fn tx_amount(&self) -> MonetaryAmount {
// ...
}
fn tx(&self) -> Option<&Transaction> {
// ...
}
fn tag() -> &'static str {
"example_line_item"
}
}
Decimal (for precision) and MonetaryAmount (for currency amounts).Transaction record.TransactionCategory to provide flexible classification of each line item for auditing or data aggregation.Contributions are welcome. Please submit issues and pull requests on GitHub.
Licensed under either of
at your option.