| Crates.io | inventory-serde |
| lib.rs | inventory-serde |
| version | 0.3.0 |
| created_at | 2025-10-08 06:03:02.074737+00 |
| updated_at | 2025-10-09 00:38:30.672171+00 |
| description | Production-ready inventory management library for Rust with serialization, business logic, and enterprise features |
| homepage | https://github.com/ZFlareUI/Serde |
| repository | https://github.com/ZFlareUI/Serde |
| max_upload_size | |
| id | 1873520 |
| size | 639,181 |
A comprehensive, production-ready Rust library for enterprise inventory management with advanced serde serialization support. This library demonstrates sophisticated business logic, machine learning algorithms, multi-warehouse optimization, and real-time decision support capabilities used in Fortune 500 supply chain operations.
Add this to your Cargo.toml:
[dependencies]
inventory-serde = "1.0.0"
Or use cargo:
cargo add inventory-serde
use inventory_serde::{ProductBuilder, Currency, FormatSerializer};
use rust_decimal_macros::dec;
let product = ProductBuilder::new("SKU-001", "Premium Smartphone")
.category("Electronics")
.unit_cost(dec!(400.0), Currency::USD)
.weight_grams(180)
.dimensions_cm(15.0, 7.5, 0.8)
.stock_levels(5, 50, 15)?
.add_tags(vec!["premium", "smartphone"])
.build()?;
// Serialize to different formats
let json = product.to_json()?;
let toml = product.to_toml()?;
println!("Product JSON: {}", json);
use inventory_serde::{InventorySystem, Transaction, TransactionType};
use chrono::Utc;
use uuid::Uuid;
let mut inventory = InventorySystem::new();
inventory.add_product(product)?;
// Record a sale transaction
let transaction = Transaction {
id: Uuid::new_v4(),
product_id: product.id,
location_id: Uuid::new_v4(),
transaction_type: TransactionType::Shipment,
quantity: -2, // Selling 2 units
unit_cost: Some(product.unit_cost.clone()),
reference_number: Some("SALE-001".to_string()),
reason_code: None,
user_id: Some("sales_system".to_string()),
timestamp: Utc::now(),
batch_number: None,
expiry_date: None,
};
inventory.record_transaction(transaction)?;
// Get reorder recommendations
let recommendations = inventory.calculate_reorder_recommendations()?;
for rec in recommendations {
println!("Product {} needs {} units (urgency: {:.2})",
rec.product_id, rec.recommended_quantity, rec.urgency);
}
use inventory_serde::InventoryPipeline;
let pipeline = InventoryPipeline::new(products, inventory_snapshots, transactions);
// Filter and analyze data
let electronics = pipeline.filter_by_category("Electronics");
let low_stock = pipeline.filter_low_stock_products()?;
let category_values = pipeline.aggregate_value_by_category()?;
// Demand pattern analysis
let analysis = pipeline.analyze_demand_patterns(product_id)?;
match analysis.recommended_strategy {
RecommendedStrategy::SeasonalPlanning => {
println!("Product shows seasonal patterns - plan inventory accordingly");
}
RecommendedStrategy::SafetyStockIncrease => {
println!("High volatility detected - consider increasing safety stock");
}
_ => {}
}
use inventory_serde::{ProductList, SupplierList, SerializationFormat, SerializationUtils};
let product_list = ProductList::new(products);
// Serialize to different formats
let json = product_list.to_json()?;
let toml = product_list.to_toml()?;
let csv = product_list.to_csv()?;
// Auto-detect format and convert
let detected_format = SerializationUtils::auto_detect_format(&json);
let converted_csv = SerializationUtils::convert_format::<ProductList>(
&json,
SerializationFormat::Json,
SerializationFormat::Csv
)?;
Calculates optimal order quantities using the formula:
EOQ = √((2 × D × S) / H)
Where D = annual demand, S = ordering cost, H = holding cost per unit per year
Advanced machine learning and statistical models for enterprise-grade demand prediction with production-level accuracy and performance:
Supported Algorithms:
Production Features:
Implementation Example:
use inventory_serde::{MLPredictionEngine, ForecastModel, ForecastAccuracy};
// Initialize ML engine with ensemble configuration
let mut ml_engine = MLPredictionEngine::new();
// Historical demand data (12 months)
let demand_history = vec![
120.0, 135.0, 128.0, 142.0, 155.0, 160.0,
170.0, 180.0, 175.0, 190.0, 200.0, 210.0
];
// Feature matrix: [month, trend, seasonality_factor, economic_indicator]
let features = vec![
vec![1.0, 0.1, 0.95, 1.02], vec![2.0, 0.12, 0.98, 1.03],
vec![3.0, 0.11, 1.05, 1.01], vec![4.0, 0.13, 1.08, 1.04],
// ... additional feature vectors
];
// Train neural network model
let model_id = ml_engine.train_demand_prediction_model(&demand_history, &features)?;
// Generate 3-month forecast with confidence intervals
let forecast = ml_engine.predict(&model_id, &[13.0, 0.15, 1.12, 1.05])?;
println!("Next month demand forecast: {:.2} units", forecast);
// Evaluate model performance
let performance = ml_engine.model_performance.get(&model_id).unwrap();
println!("Model MAPE: {:.2}%", performance.accuracy_metrics.mape * 100.0);
println!("R-squared: {:.3}", performance.accuracy_metrics.r_squared);
Advanced Ensemble Forecasting:
// Create ensemble model with multiple algorithms
let holt_winters = ForecastModel::HoltWinters {
alpha: 0.3, beta: 0.1, gamma: 0.2,
seasonal_periods: 12, multiplicative: false,
};
let arima = ForecastModel::ARIMA {
autoregressive_order: 2, differencing_order: 1,
moving_average_order: 1,
coefficients: ARIMACoefficients {
ar_coefficients: vec![0.7, -0.2],
ma_coefficients: vec![0.5],
constant: 0.1,
},
};
let ensemble = ForecastModel::EnsembleModel {
models: vec![
(holt_winters, 0.4), // 40% weight
(arima, 0.6), // 60% weight
],
};
// Generate ensemble forecast
let ensemble_forecast = ensemble.forecast(&demand_history, 6)?;
for (month, forecast) in ensemble_forecast.iter().enumerate() {
println!("Month {}: {:.1} units", month + 1, forecast);
}
Integration with Inventory Policies:
Automatically classifies inventory using the Pareto principle:
Statistical approach using demand variability:
Safety Stock = Z × σ × √L
Where Z = service level factor, σ = demand standard deviation, L = lead time
src/
├── lib.rs # Public API and documentation
├── models.rs # Core data models with serde support
├── algorithms.rs # Business logic and mathematical algorithms
├── builders.rs # Type-safe builder patterns
├── pipelines.rs # Data transformation and analytics
├── serialization.rs # Multi-format serialization support
├── errors.rs # Comprehensive error handling
└── tests.rs # Extensive test coverage
let margin = product.profit_margin()?;
println!("Profit margin: {:.2}%", margin);
let volume = product.volume_cm3();
println!("Storage volume: {:.2} cm³", volume);
let usd_price = Money::new(dec!(100.0), Currency::USD);
let eur_price = usd_price.convert_to(Currency::EUR, dec!(0.85));
println!("Converted price: {}", eur_price.format()); // €85.00
let location = LocationBuilder::new("WAREHOUSE-01")
.zone("A").aisle("12").shelf("C").bin("03")
.capacity_units(1000)
.temperature_controlled(true)
.build()?;
println!("Utilization: {:.1}%", location.utilization_percentage());
The library includes comprehensive tests covering:
Run tests with:
cargo test
Complex Data Model: Inventory management domain with realistic business entities
Production Library Features: Multi-format serialization, validation, error handling
Real Algorithms: EOQ, demand forecasting, ABC analysis, statistical methods
No Placeholders: Complete implementations with actual business logic
Type Safety: Builder patterns, comprehensive validation, proper error types
Thread Safety: Immutable data structures where applicable
Documentation: Comprehensive API docs with examples
Testing: 21 test cases covering all major functionality
The library uses a comprehensive error system:
pub enum InventoryError {
Validation { message: String },
Serialization { message: String },
Product { message: String },
Supplier { message: String },
Calculation { message: String },
Currency { message: String },
Pipeline { message: String },
Builder { message: String },
}
All operations return InventoryResult<T> for proper error propagation.
This library demonstrates production-ready Rust code with:
This project is licensed under the MIT OR Apache-2.0 license.
This is a demonstration library showcasing advanced Rust and serde capabilities. The code serves as an example of:
Built with Love and Rust