Tiered pricing and discounts for Rust applications
| Tier | domain |
| Role | unclassified (baselined) |
| Path | crates/domain/pricing |
| Edition | 2021 |
| Targets | domain_pricing |
| Public items | 58 across 0 modules |
| Tests | 30 |
What it is for
Tiered pricing and discount library crates for Rust applications.
This crate provides:
Tiertrait for defining custom pricing tiersTieredPricefor prices that vary by customer tierPriceBreakfor quantity-based pricing (bulk discounts)Discountfor applying discounts (percentage or fixed)PricingCalculatorfor computing final prices with all rules
# Example
use domain_pricing::{StandardTier, TieredPrice, PricingCalculator};
use rust_decimal::Decimal;
// Create tiered pricing
let price = TieredPrice::new(
Decimal::from(100), // Regular price
Decimal::from(85), // Member price
Decimal::from(70), // VIP price
);
// Get price for a tier
let member_price = price.price_for_tier(StandardTier::Member);
Capabilities
B2BTier
Tiered pricing and discount library crates for Rust applications.
| Item |
|---|
pub enum B2BTier |
B2BTier :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result |
Discount:Discount
Tiered pricing and discount library crates for Rust applications.
| Item |
|---|
pub struct Discount |
Discount:apply
Tiered pricing and discount library crates for Rust applications.
| Item |
|---|
Discount :: fn apply(& self, price : Decimal) -> Decimal |
Discount:calculate
Tiered pricing and discount library crates for Rust applications.
| Item |
|---|
Discount :: fn calculate(& self, price : Decimal) -> Decimal |
Discount:can
Tiered pricing and discount library crates for Rust applications.
| Item |
|---|
Discount :: fn can_apply_to(& self, order_value : Decimal) -> bool |
Discount:fixed
Tiered pricing and discount library crates for Rust applications.
| Item |
|---|
Discount :: fn fixed(name : impl Into <String>, amount : Decimal) -> Self |
Discount:is
Tiered pricing and discount library crates for Rust applications.
| Item |
|---|
Discount :: fn is_valid(& self) -> bool |
Discount:percentage
Tiered pricing and discount library crates for Rust applications.
| Item |
|---|
Discount :: fn percentage(name : impl Into <String>, rate : Decimal) -> Self |
Discount:record
Tiered pricing and discount library crates for Rust applications.
| Item |
|---|
Discount :: fn record_usage(& mut self) |
Discount:with
Tiered pricing and discount library crates for Rust applications.
| Item |
|---|
Discount :: fn with_code(mut self, code : impl Into <String>) -> Self |
Discount :: fn with_min_order(mut self, min : Decimal) -> Self |
Discount :: fn with_max_discount(mut self, max : Decimal) -> Self |
Discount :: fn with_validity(mut self, from : DateTime <Utc>, until : DateTime <Utc>) -> Self |
Discount :: fn with_usage_limit(mut self, limit : i32) -> Self |
DiscountType
Tiered pricing and discount library crates for Rust applications.
| Item |
|---|
pub enum DiscountType |
DiscountType :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result |
FlexTieredPrice
Tiered pricing and discount library crates for Rust applications.
| Item |
|---|
pub struct FlexTieredPrice |
FlexTieredPrice :: fn new(base_price : Decimal) -> Self |
FlexTieredPrice :: fn with_tier_price(mut self, tier : impl Into <String>, price : Decimal) -> Self |
FlexTieredPrice :: fn price_for_tier(& self, tier : & str) -> Decimal |
MinimumCharge
Tiered pricing and discount library crates for Rust applications.
| Item |
|---|
pub struct MinimumCharge |
MinimumCharge :: fn new(amount : Decimal) -> Self |
MinimumCharge :: fn with_description(mut self, desc : impl Into <String>) -> Self |
MinimumCharge :: fn apply(& self, price : Decimal) -> Decimal |
PriceBreak
Tiered pricing and discount library crates for Rust applications.
| Item |
|---|
pub struct PriceBreak |
PriceBreak :: fn new(min_quantity : i32, unit_price : Decimal) -> Self |
PriceBreak :: fn with_max(mut self, max : i32) -> Self |
PriceBreak :: fn with_description(mut self, desc : impl Into <String>) -> Self |
PriceBreak :: fn contains(& self, quantity : i32) -> bool |
PriceCalculation
Tiered pricing and discount library crates for Rust applications.
| Item |
|---|
pub struct PriceCalculation |
PriceCalculation :: fn total_savings(& self) -> Decimal |
PriceCalculation :: fn effective_unit_price(& self) -> Decimal |
PricingCalculator
Tiered pricing and discount library crates for Rust applications.
| Item |
|---|
pub struct PricingCalculator |
PricingCalculator :: fn new() -> Self |
PricingCalculator :: fn with_minimum_charge(mut self, minimum : MinimumCharge) -> Self |
PricingCalculator :: fn with_discount(mut self, discount : Discount) -> Self |
PricingCalculator :: fn calculate(& self, tiered_price : & TieredPrice, tier : StandardTier, quantity : i32,) -> PriceCalculation |
PricingCalculator :: fn calculate_with_quantity_pricing(& self, quantity_pricing : & QuantityPricing, quantity : i32,) -> PriceCalculation |
PricingError
Tiered pricing and discount library crates for Rust applications.
| Item |
|---|
pub enum PricingError |
QuantityPricing
Tiered pricing and discount library crates for Rust applications.
| Item |
|---|
pub struct QuantityPricing |
QuantityPricing :: fn new(base_price : Decimal) -> Self |
QuantityPricing :: fn with_break(mut self, price_break : PriceBreak) -> Self |
QuantityPricing :: fn unit_price_for_quantity(& self, quantity : i32) -> Decimal |
QuantityPricing :: fn total_for_quantity(& self, quantity : i32) -> Decimal |
QuantityPricing :: fn break_for_quantity(& self, quantity : i32) -> Option <& PriceBreak> |
Result
Tiered pricing and discount library crates for Rust applications.
| Item |
|---|
pub type Result<T>: std::result::Result <T, PricingError> |
StandardTier
Tiered pricing and discount library crates for Rust applications.
| Item |
|---|
pub enum StandardTier |
StandardTier :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result |
StandardTier :: fn discount_rate(& self) -> Decimal |
StandardTier :: fn all() -> & 'static Self |
TieredPrice
Tiered pricing and discount library crates for Rust applications.
| Item |
|---|
pub struct TieredPrice |
TieredPrice :: fn new(regular : Decimal, member : Decimal, vip : Decimal) -> Self |
TieredPrice :: fn flat(price : Decimal) -> Self |
TieredPrice :: fn from_base_with_discounts(base : Decimal, member_discount : Decimal, vip_discount : Decimal,) -> Self |
TieredPrice :: fn price_for_tier(& self, tier : StandardTier) -> Decimal |
TieredPrice :: fn discount_for_tier(& self, tier : StandardTier) -> Decimal |
TieredPrice :: fn discount_rate_for_tier(& self, tier : StandardTier) -> Decimal |
How to use it
From this crate's own rustdoc:
use domain_pricing::{StandardTier, TieredPrice, PricingCalculator};
use rust_decimal::Decimal;
// Create tiered pricing
let price = TieredPrice::new(
Decimal::from(100), // Regular price
Decimal::from(85), // Member price
Decimal::from(70), // VIP price
);
// Get price for a tier
let member_price = price.price_for_tier(StandardTier::Member);
Module structure
No public modules: the crate root is its whole surface.
Public surface
`crate root`
| Item | What it is |
|---|---|
pub enum PricingError | Errors that can occur with pricing operations. |
pub type Result<T>: std::result::Result <T, PricingError> | Result type for pricing operations. |
pub enum StandardTier | Standard pricing tiers (Regular, Member, VIP) |
StandardTier :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result | — |
StandardTier :: fn discount_rate(& self) -> Decimal | Returns the discount percentage for this tier (0.0 to 1.0). |
StandardTier :: fn all() -> & 'static Self | Returns all tiers in order from lowest to highest discount. |
pub enum B2BTier | Business-to-business pricing tiers. |
B2BTier :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result | — |
pub struct TieredPrice | Price that varies by customer tier |
TieredPrice :: fn new(regular : Decimal, member : Decimal, vip : Decimal) -> Self | Creates a new tiered price. |
TieredPrice :: fn flat(price : Decimal) -> Self | Creates a flat price (same for all tiers). |
TieredPrice :: fn from_base_with_discounts(base : Decimal, member_discount : Decimal, vip_discount : Decimal,) -> Self | Creates tiered pricing from a base price with percentage discounts. |
TieredPrice :: fn price_for_tier(& self, tier : StandardTier) -> Decimal | Gets the price for a specific tier. |
TieredPrice :: fn discount_for_tier(& self, tier : StandardTier) -> Decimal | Returns the discount amount for a tier compared to regular price. |
TieredPrice :: fn discount_rate_for_tier(& self, tier : StandardTier) -> Decimal | Returns the discount percentage for a tier (0.0 to 1.0). |
pub struct FlexTieredPrice | Flexible tiered pricing using a HashMap for custom tiers. |
FlexTieredPrice :: fn new(base_price : Decimal) -> Self | Creates a new flexible tiered price. |
FlexTieredPrice :: fn with_tier_price(mut self, tier : impl Into <String>, price : Decimal) -> Self | Sets a price for a specific tier. |
FlexTieredPrice :: fn price_for_tier(& self, tier : & str) -> Decimal | Gets the price for a tier (returns base if tier not found). |
pub struct PriceBreak | A price break for quantity-based pricing. |
PriceBreak :: fn new(min_quantity : i32, unit_price : Decimal) -> Self | Creates a new price break. |
PriceBreak :: fn with_max(mut self, max : i32) -> Self | Sets the maximum quantity. |
PriceBreak :: fn with_description(mut self, desc : impl Into <String>) -> Self | Sets the description. |
PriceBreak :: fn contains(& self, quantity : i32) -> bool | Checks if a quantity falls within this break. |
pub struct QuantityPricing | Quantity-based pricing schedule (price breaks). |
QuantityPricing :: fn new(base_price : Decimal) -> Self | Creates a new quantity pricing schedule. |
QuantityPricing :: fn with_break(mut self, price_break : PriceBreak) -> Self | Adds a price break. |
QuantityPricing :: fn unit_price_for_quantity(& self, quantity : i32) -> Decimal | Gets the unit price for a quantity. |
QuantityPricing :: fn total_for_quantity(& self, quantity : i32) -> Decimal | Calculates the total price for a quantity. |
QuantityPricing :: fn break_for_quantity(& self, quantity : i32) -> Option <& PriceBreak> | Returns the applicable price break for a quantity. |
pub enum DiscountType | Type of discount. |
DiscountType :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result | — |
pub struct Discount | A discount that can be applied to a price. |
Discount :: fn percentage(name : impl Into <String>, rate : Decimal) -> Self | Creates a percentage discount. |
Discount :: fn fixed(name : impl Into <String>, amount : Decimal) -> Self | Creates a fixed amount discount. |
Discount :: fn with_code(mut self, code : impl Into <String>) -> Self | Sets the discount code. |
Discount :: fn with_min_order(mut self, min : Decimal) -> Self | Sets the minimum order value. |
Discount :: fn with_max_discount(mut self, max : Decimal) -> Self | Sets the maximum discount amount. |
Discount :: fn with_validity(mut self, from : DateTime <Utc>, until : DateTime <Utc>) -> Self | Sets the validity period. |
Discount :: fn with_usage_limit(mut self, limit : i32) -> Self | Sets the usage limit. |
Discount :: fn is_valid(& self) -> bool | Checks if the discount is currently valid. |
Discount :: fn can_apply_to(& self, order_value : Decimal) -> bool | Checks if the discount can be applied to an order value. |
Discount :: fn calculate(& self, price : Decimal) -> Decimal | Calculates the discount amount for a given price. |
Discount :: fn apply(& self, price : Decimal) -> Decimal | Applies the discount to a price. |
Discount :: fn record_usage(& mut self) | Increments the usage count. |
pub struct MinimumCharge | Minimum charge configuration. |
MinimumCharge :: fn new(amount : Decimal) -> Self | Creates a new minimum charge. |
MinimumCharge :: fn with_description(mut self, desc : impl Into <String>) -> Self | Sets the description. |
MinimumCharge :: fn apply(& self, price : Decimal) -> Decimal | Applies the minimum charge to a calculated price. |
pub struct PriceCalculation | Result of a price calculation. |
PriceCalculation :: fn total_savings(& self) -> Decimal | Returns the total savings. |
PriceCalculation :: fn effective_unit_price(& self) -> Decimal | Returns the effective unit price. |
pub struct PricingCalculator | Pricing calculator that combines tiers, quantities, discounts, and minimums. |
PricingCalculator :: fn new() -> Self | Creates a new pricing calculator. |
PricingCalculator :: fn with_minimum_charge(mut self, minimum : MinimumCharge) -> Self | Sets the minimum charge. |
PricingCalculator :: fn with_discount(mut self, discount : Discount) -> Self | Adds a discount. |
PricingCalculator :: fn calculate(& self, tiered_price : & TieredPrice, tier : StandardTier, quantity : i32,) -> PriceCalculation | Calculates the price for a tiered price and quantity. |
PricingCalculator :: fn calculate_with_quantity_pricing(& self, quantity_pricing : & QuantityPricing, quantity : i32,) -> PriceCalculation | Calculates price with quantity-based pricing. |
No pub use re-exports: every item above is declared in this crate.
Boundary
Depends on no other workspace tier.
Shares tier domain with 41 other crates: domain-agreements, domain-ai-report, domain-billing, domain-catalog, domain-classify, domain-comments, domain-competitive-intel, domain-contact, … (41 total).
_What this crate deliberately does NOT own is a judgment. No committed registry records one for it, so none is stated here._
Where it sits
| Tier (ontology) | domain |
| Architectural role (taxonomy) | unclassified (baselined) |
| Location | crates/domain/pricing |
| Vocabulary in force (lexicon) | current |
Dependencies
Runtime, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
chrono | ^0.4 | serde | no | always |
rust_decimal | ^1 | serde | no | always |
serde | ^1 | derive | no | always |
serde_json | ^1 | — | no | always |
thiserror | ^2 | — | no | always |
uuid | ^1 | v4, v7, serde, js | no | always |
Development, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
rust_decimal_macros | ^1 | — | no | always |
tokio | ^1 | full | no | always |
Build. None.
Depended on by. Nothing in this workspace.
Feature flags
No Cargo features are defined: every capability is unconditional, so no consumer can receive a half-wired crate.
Targets
| Kind | Name | Source |
|---|---|---|
| lib | domain_pricing | `src/lib.rs` |
Error model
| Error type | Named by |
|---|---|
PricingError | Result |
Operational characteristics
| Property | Evidence |
|---|---|
| async public surface | none detected |
| async runtime | none detected |
| database access | none detected |
| network I/O | none detected |
| unsafe code | none detected |
| environment variables | none detected |
No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.
Configuration
No environment variable is read with a literal name anywhere in this crate. A variable whose key is computed at run time cannot be listed here, and is not claimed to be absent.
Related capabilities
No workspace crate depends on this one.
Verification
| Kind | Count |
|---|---|
| Unit tests | 30 |
| Integration tests | 0 |
| Examples | 0 |
| Doctests | 1 |
Evidence by module. How often each public module is named by something executable.
| Module | Tests | Examples | Consumers |
|---|---|---|---|
crate root | 13 | 0 | 0 |
What the tests establish, by name:
test_discount_fixed—src/lib.rstest_discount_percentage—src/lib.rstest_discount_serialization—src/lib.rstest_discount_usage_limit—src/lib.rstest_discount_with_code—src/lib.rstest_discount_with_max—src/lib.rstest_discount_with_min_order—src/lib.rstest_flex_tiered_price—src/lib.rstest_minimum_charge—src/lib.rstest_price_break_contains—src/lib.rstest_price_calculation_effective_unit_price—src/lib.rstest_price_calculation_savings—src/lib.rstest_pricing_calculator_simple—src/lib.rstest_pricing_calculator_with_discount—src/lib.rstest_pricing_calculator_with_minimum—src/lib.rstest_pricing_calculator_with_quantity—src/lib.rstest_pricing_calculator_with_quantity_pricing—src/lib.rstest_quantity_pricing_basic—src/lib.rstest_quantity_pricing_serialization—src/lib.rstest_quantity_pricing_total—src/lib.rstest_standard_tier_all—src/lib.rstest_standard_tier_default—src/lib.rstest_standard_tier_display—src/lib.rstest_tiered_price_discount_for_tier—src/lib.rstest_tiered_price_discount_rate—src/lib.rstest_tiered_price_flat—src/lib.rstest_tiered_price_for_tier—src/lib.rstest_tiered_price_from_base_with_discounts—src/lib.rstest_tiered_price_new—src/lib.rstest_tiered_price_serialization—src/lib.rs
Documentation coverage
| Measure | Documented | Total |
|---|---|---|
| Public items with rustdoc | 55 | 58 |
Public modules with a //! block | 0 | 0 |
pie showData
title Public items with rustdoc
"Documented" : 55
"No rustdoc detected" : 3
Metrics
| Metric | Value |
|---|---|
| Rust source files | 1 |
| Source lines | 1129 |
| Code lines | 786 |
| Public API items | 58 |
| Public modules | 0 |
| Tests | 30 |
| Examples | 0 |
| Cargo features | 0 |
| Direct runtime dependencies | 6 |
| Workspace reverse dependencies | 0 |
pie showData
title Public API by kind
"enum" : 4
"method" : 45
"struct" : 8
"type alias" : 1
pie showData
title Rust source composition
"Code" : 786
"Blank or comment" : 343
Generation
Rendered by tools-corpus corpus readme from repository evidence alone, renderer schema 2, lexicon current. No model, network service or database was consulted. Regenerate with tools-corpus corpus readme --write; verify with --check.