8 releases
| new 0.6.0 | Feb 4, 2026 |
|---|---|
| 0.2.6 | Jan 28, 2026 |
| 0.1.9 | Jan 10, 2026 |
| 0.1.7 | Dec 20, 2025 |
#849 in Magic Beans
Used in 2 crates
1MB
19K
SLoC
StateSet Core
Pure domain models and business logic for commerce operations. This crate has no I/O dependencies - just data structures and validation.
Overview
stateset-core provides the foundational types for the StateSet iCommerce platform:
- Domain Models: Strongly-typed structs for all commerce entities
- Repository Traits: Abstract interfaces for data access
- Error Types: Comprehensive error handling with categorization
- Validation: Composable validation builders and traits
- Events: Domain event types for event-driven architectures
Core Domains
| Domain | Description |
|---|---|
| Orders | Order management with line items, status tracking |
| Inventory | Stock tracking, reservations, adjustments |
| Customers | Customer profiles, addresses, contact info |
| Products | Product catalog with variants, pricing |
| Returns | Return processing, refunds, RMA |
| Manufacturing | Bill of Materials (BOM), Work Orders |
| Shipments | Shipping, tracking, carrier integration |
| Payments | Payment processing, refunds |
| Subscriptions | Recurring billing, subscription plans |
| Promotions | Discounts, coupons, promotional campaigns |
| Tax | Multi-jurisdiction tax calculation |
| Currency | Multi-currency support, exchange rates |
Error Handling
All operations return Result<T, CommerceError>. Errors can be categorized:
use stateset_core::CommerceError;
fn handle_error(err: &CommerceError) {
if err.is_not_found() {
// Handle not found errors (404)
} else if err.is_validation() {
// Handle validation errors (400)
} else if err.is_conflict() {
// Handle conflict errors (409)
} else if err.is_database() {
// Handle database errors (500)
} else if err.is_retryable() {
// Retry the operation
}
}
Validation
Use ValidationBuilder for composable validations:
use stateset_core::{ValidationBuilder, Result};
fn validate_order(email: &str, quantity: i32) -> Result<()> {
ValidationBuilder::new()
.email("email", email)
.positive_i32("quantity", quantity)
.build()
}
Or implement the Validate trait for domain models:
use stateset_core::{Validate, ValidationBuilder, Result};
struct OrderInput {
email: String,
quantity: i32,
}
impl Validate for OrderInput {
fn validate(&self) -> Result<()> {
ValidationBuilder::new()
.email("email", &self.email)
.positive_i32("quantity", self.quantity)
.build()
}
}
// Use with method chaining
// let input = OrderInput { ... }.validated()?;
Example
use stateset_core::prelude::*;
use rust_decimal_macros::dec;
// Create an order input
let order = CreateOrder {
customer_id: uuid::Uuid::new_v4(),
items: vec![CreateOrderItem {
sku: "SKU-001".to_string(),
name: "Widget".to_string(),
quantity: 2,
unit_price: dec!(29.99),
..Default::default()
}],
..Default::default()
};
Feature Flags
embeddings- Enable vector search via embedding servicesmetrics- Enable Prometheus metrics support
Dependencies
~5–21MB
~233K SLoC