Overview
EUXIS Commons is the shared utility layer that powers every crate in the EUXIS ecosystem. Rather than scattering helper functions across repositories or pulling in heavyweight frameworks, Commons provides a curated, feature-gated set of modules that compile only what you use.
Why Commons?
| Concern | Without Commons | With Commons |
|---|---|---|
| Error Types | Each crate invents its own | Unified CommonError + CommonResult |
| Config Loading | Raw toml::from_str everywhere |
Config::from_file with typed getters |
| Retry Logic | Copy-pasted sleep loops | Configurable backoff strategies |
| ID Generation | uuid + rand dependency bloat |
Zero-dep timestamp, hex, and short IDs |
| Path Handling | Manual ~ expansion, WSL hacks |
resolve_path, to_wsl_path, from_wsl_path |
| Validation | Ad-hoc regex checks | is_valid_email, is_valid_url, is_valid_semver |
Architecture
graph TD
A[Downstream Crate] -->|use commons::prelude::*| B{Feature Gates}
B --> C[config — TOML loading & typed getters]
B --> D[error — CommonError & Result aliases]
B --> E[logging — Timestamped structured logging]
B --> F[time — Duration parsing & formatting]
B --> G[collections — LRU cache]
B --> H[validation — Email, URL, semver, IP]
B --> I[retry — Exponential & linear backoff]
B --> J[id — Timestamp, hex, short & UUID-like IDs]
B --> K[env — Typed env vars & environment detection]
B --> L[fs — Tilde expansion, WSL paths, ensure_dir]
Getting Started
Pre-flight Checklist
- Rust 1.88.0+ installed (
rustc --version) - Cargo package manager ready
Install
Add euxis-commons to your project:
Or with specific features only:
[]
= { = "0.0.2", = false, = ["error", "time"] }
Features
All features are enabled by default via the full meta-feature. Disable default-features and pick only what you need to minimise compile times.
| Feature | Description | Dependencies |
|---|---|---|
config |
TOML configuration loading with typed getters and Vec<T> array extraction |
serde, toml |
error |
Common error types and Result aliases |
thiserror |
logging |
Simple timestamped, level-filtered structured logging | time |
time |
Duration parsing (including compound "1h 30m") and formatting |
— |
collections |
LRU cache with capacity-bounded eviction | — |
validation |
Email, URL (with localhost + port), semver (with pre-release), IP, identifier checks | — |
retry |
Retry with constant, linear, and exponential backoff + jitter | — |
id |
Timestamp-sortable, random hex, short base62, and UUID-like ID generation | — |
env |
Typed env var access, boolean parsing, list splitting, environment detection | — |
fs |
Tilde expansion, ensure_dir, WSL detection, bidirectional WSL path translation |
— |
Usage
use ;
use Config;
use Deserialize;
let config: AppConfig = from_file?.parse?;
Arrays are supported out of the box:
let hosts: = config.get;
use ;
use Duration;
// Single unit
let d = parse_duration.unwrap;
assert_eq!;
// Compound expression
let d = parse_duration.unwrap;
assert_eq!;
let formatted = format_duration;
assert_eq!;
use ;
use Duration;
let config = new
.max_attempts
.backoff;
let result = retry;
use ;
let ts_id = generate_id; // 20-char sortable
let hex_id = generate_id; // 32-char hex
let short = generate_id; // 12-char base62
let user_id = generate_prefixed_id; // "usr_A1b2C3d4E5f6"
use *;
assert!;
assert!;
assert!;
assert!;
assert!;
use ;
// Tilde expansion
let path = resolve_path;
// WSL path translation (bidirectional)
let wsl = to_wsl_path; // /mnt/c/Users/Name/file.txt
let win = from_wsl_path; // C:\Users\Name\file.txt
// Create nested directories
ensure_dir.unwrap;
use *;
// All public types from enabled features are now in scope
let mut cache = new;
cache.insert;
Reusable CI Workflows
Commons ships reusable GitHub Actions workflows that downstream crates can call directly:
# .github/workflows/ci.yml in your downstream crate
jobs:
ci:
uses: sebastienrousseau/commons/.github/workflows/ci.yml@main
coverage:
uses: sebastienrousseau/commons/.github/workflows/coverage.yml@main
secrets: inherit
audit:
uses: sebastienrousseau/commons/.github/workflows/audit.yml@main
Safety & Compliance
#![deny(unsafe_code)]— No unsafe blocks anywhere in the crate- MIRI-verified — CI runs
cargo miri teston every push - Pedantic linting — Survives
clippy::pedantic,clippy::nursery, andclippy::cargo - 95%+ code coverage — Cross-platform matrix (Linux, macOS, Windows)
Minimum Supported Rust Version
This crate requires Rust 1.88.0 or later (edition = "2024").
License
Licensed under the MIT License or Apache-2.0, at your option. See LICENSE-MIT or LICENSE-APACHE for details.