domain tier

domain-pricing

Tiered pricing and discounts for Rust applications

Tiered pricing and discounts for Rust applications

Tierdomain
Roleunclassified (baselined)
Pathcrates/domain/pricing
Edition2021
Targetsdomain_pricing
Public items58 across 0 modules
Tests30

What it is for

Tiered pricing and discount library crates for Rust applications.

This crate provides:

# 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`

ItemWhat it is
pub enum PricingErrorErrors that can occur with pricing operations.
pub type Result<T>: std::result::Result <T, PricingError>Result type for pricing operations.
pub enum StandardTierStandard pricing tiers (Regular, Member, VIP)
StandardTier :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result
StandardTier :: fn discount_rate(& self) -> DecimalReturns the discount percentage for this tier (0.0 to 1.0).
StandardTier :: fn all() -> & 'static SelfReturns all tiers in order from lowest to highest discount.
pub enum B2BTierBusiness-to-business pricing tiers.
B2BTier :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result
pub struct TieredPricePrice that varies by customer tier
TieredPrice :: fn new(regular : Decimal, member : Decimal, vip : Decimal) -> SelfCreates a new tiered price.
TieredPrice :: fn flat(price : Decimal) -> SelfCreates a flat price (same for all tiers).
TieredPrice :: fn from_base_with_discounts(base : Decimal, member_discount : Decimal, vip_discount : Decimal,) -> SelfCreates tiered pricing from a base price with percentage discounts.
TieredPrice :: fn price_for_tier(& self, tier : StandardTier) -> DecimalGets the price for a specific tier.
TieredPrice :: fn discount_for_tier(& self, tier : StandardTier) -> DecimalReturns the discount amount for a tier compared to regular price.
TieredPrice :: fn discount_rate_for_tier(& self, tier : StandardTier) -> DecimalReturns the discount percentage for a tier (0.0 to 1.0).
pub struct FlexTieredPriceFlexible tiered pricing using a HashMap for custom tiers.
FlexTieredPrice :: fn new(base_price : Decimal) -> SelfCreates a new flexible tiered price.
FlexTieredPrice :: fn with_tier_price(mut self, tier : impl Into <String>, price : Decimal) -> SelfSets a price for a specific tier.
FlexTieredPrice :: fn price_for_tier(& self, tier : & str) -> DecimalGets the price for a tier (returns base if tier not found).
pub struct PriceBreakA price break for quantity-based pricing.
PriceBreak :: fn new(min_quantity : i32, unit_price : Decimal) -> SelfCreates a new price break.
PriceBreak :: fn with_max(mut self, max : i32) -> SelfSets the maximum quantity.
PriceBreak :: fn with_description(mut self, desc : impl Into <String>) -> SelfSets the description.
PriceBreak :: fn contains(& self, quantity : i32) -> boolChecks if a quantity falls within this break.
pub struct QuantityPricingQuantity-based pricing schedule (price breaks).
QuantityPricing :: fn new(base_price : Decimal) -> SelfCreates a new quantity pricing schedule.
QuantityPricing :: fn with_break(mut self, price_break : PriceBreak) -> SelfAdds a price break.
QuantityPricing :: fn unit_price_for_quantity(& self, quantity : i32) -> DecimalGets the unit price for a quantity.
QuantityPricing :: fn total_for_quantity(& self, quantity : i32) -> DecimalCalculates 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 DiscountTypeType of discount.
DiscountType :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result
pub struct DiscountA discount that can be applied to a price.
Discount :: fn percentage(name : impl Into <String>, rate : Decimal) -> SelfCreates a percentage discount.
Discount :: fn fixed(name : impl Into <String>, amount : Decimal) -> SelfCreates a fixed amount discount.
Discount :: fn with_code(mut self, code : impl Into <String>) -> SelfSets the discount code.
Discount :: fn with_min_order(mut self, min : Decimal) -> SelfSets the minimum order value.
Discount :: fn with_max_discount(mut self, max : Decimal) -> SelfSets the maximum discount amount.
Discount :: fn with_validity(mut self, from : DateTime <Utc>, until : DateTime <Utc>) -> SelfSets the validity period.
Discount :: fn with_usage_limit(mut self, limit : i32) -> SelfSets the usage limit.
Discount :: fn is_valid(& self) -> boolChecks if the discount is currently valid.
Discount :: fn can_apply_to(& self, order_value : Decimal) -> boolChecks if the discount can be applied to an order value.
Discount :: fn calculate(& self, price : Decimal) -> DecimalCalculates the discount amount for a given price.
Discount :: fn apply(& self, price : Decimal) -> DecimalApplies the discount to a price.
Discount :: fn record_usage(& mut self)Increments the usage count.
pub struct MinimumChargeMinimum charge configuration.
MinimumCharge :: fn new(amount : Decimal) -> SelfCreates a new minimum charge.
MinimumCharge :: fn with_description(mut self, desc : impl Into <String>) -> SelfSets the description.
MinimumCharge :: fn apply(& self, price : Decimal) -> DecimalApplies the minimum charge to a calculated price.
pub struct PriceCalculationResult of a price calculation.
PriceCalculation :: fn total_savings(& self) -> DecimalReturns the total savings.
PriceCalculation :: fn effective_unit_price(& self) -> DecimalReturns the effective unit price.
pub struct PricingCalculatorPricing calculator that combines tiers, quantities, discounts, and minimums.
PricingCalculator :: fn new() -> SelfCreates a new pricing calculator.
PricingCalculator :: fn with_minimum_charge(mut self, minimum : MinimumCharge) -> SelfSets the minimum charge.
PricingCalculator :: fn with_discount(mut self, discount : Discount) -> SelfAdds a discount.
PricingCalculator :: fn calculate(& self, tiered_price : & TieredPrice, tier : StandardTier, quantity : i32,) -> PriceCalculationCalculates the price for a tiered price and quantity.
PricingCalculator :: fn calculate_with_quantity_pricing(& self, quantity_pricing : & QuantityPricing, quantity : i32,) -> PriceCalculationCalculates 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)
Locationcrates/domain/pricing
Vocabulary in force (lexicon)current

Dependencies

Runtime, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
chrono^0.4serdenoalways
rust_decimal^1serdenoalways
serde^1derivenoalways
serde_json^1noalways
thiserror^2noalways
uuid^1v4, v7, serde, jsnoalways

Development, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
rust_decimal_macros^1noalways
tokio^1fullnoalways

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

KindNameSource
libdomain_pricing`src/lib.rs`

Error model

Error typeNamed by
PricingErrorResult

Operational characteristics

PropertyEvidence
async public surfacenone detected
async runtimenone detected
database accessnone detected
network I/Onone detected
unsafe codenone detected
environment variablesnone 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.

No workspace crate depends on this one.

Verification

KindCount
Unit tests30
Integration tests0
Examples0
Doctests1

Evidence by module. How often each public module is named by something executable.

ModuleTestsExamplesConsumers
crate root1300

What the tests establish, by name:

Documentation coverage

MeasureDocumentedTotal
Public items with rustdoc5558
Public modules with a //! block00
pie showData
    title Public items with rustdoc
    "Documented" : 55
    "No rustdoc detected" : 3

Metrics

MetricValue
Rust source files1
Source lines1129
Code lines786
Public API items58
Public modules0
Tests30
Examples0
Cargo features0
Direct runtime dependencies6
Workspace reverse dependencies0
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.

All domain · Manual