Commons
Shared Rust utilities and common patterns for the Sebastien Rousseau ecosystem.
Overview
Commons provides reusable components, traits, and utilities used across multiple Rust projects in the ecosystem. It serves as the foundation library for consistent error handling, configuration management, logging, and more.
Features
| Feature | Description | Dependencies |
|---|---|---|
config |
TOML configuration loading | serde, toml |
error |
Common error types with thiserror |
thiserror |
logging |
Simple structured logging | - |
time |
Duration parsing and formatting | - |
collections |
LRU cache and utilities | - |
By default, all features are enabled. Use default-features = false to select specific features.
Installation
[]
= { = "https://github.com/sebastienrousseau/commons" }
# Or with specific features only
= { = "https://github.com/sebastienrousseau/commons", = false, = ["error", "time"] }
Usage
Error Handling
use ;
Configuration
use Config;
use Deserialize;
let config: AppConfig = from_file?.parse?;
Time Utilities
use ;
use Duration;
let duration = parse_duration.unwrap;
assert_eq!;
let formatted = format_duration;
assert_eq!;
LRU Cache
use LruCache;
let mut cache = new;
cache.insert;
if let Some = cache.get
Logging
use ;
let mut logger = new;
logger.set_level;
logger.info;
logger.debug;
Prelude
For convenience, import common types with the prelude:
use *;
Minimum Supported Rust Version
This crate requires Rust 1.70 or later.
License
Dual-licensed under MIT and Apache-2.0.