stateset-primitives 0.7.13

Strongly-typed primitive types for StateSet iCommerce
docs.rs failed to build stateset-primitives-0.7.13
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.

stateset-primitives

Strongly-typed primitive types for commerce applications in Rust. Prevents entire classes of bugs at compile time by making it impossible to confuse an OrderId with a CustomerId, or to add Money in different currencies.

Features

  • Newtype IDs: OrderId, CustomerId, ProductId, ShipmentId, PaymentId, InventoryItemId, SubscriptionId, CartId, and 9 more — all Copy + Eq + Hash + Serialize + Display
  • Money: Amount + currency pair that prevents arithmetic across currencies
  • CurrencyCode: ISO 4217 currency codes (USD, EUR, GBP, ...) plus crypto (BTC, ETH, USDC)
  • Sku: Validated product SKU (alphanumeric + hyphen/underscore)
  • Zero unsafe code, #[deny(unsafe_code)]

Usage

use stateset_primitives::{OrderId, CustomerId, Money, CurrencyCode, Sku};
use uuid::Uuid;

// Type-safe IDs — can't accidentally swap them
let order_id: OrderId = Uuid::new_v4().into();
let customer_id: CustomerId = Uuid::new_v4().into();

// Money is currency-aware
let price = Money::new(29.99, CurrencyCode::USD);

// SKUs are validated
let sku: Sku = "WBH-001".parse().unwrap();

Feature Flags

  • std (default) — Standard library support
  • arbitrary — Enable proptest::Arbitrary for property-based testing

License

MIT OR Apache-2.0