luhtwin
Error Handling for Rust
luhtwin provides an ergonomic error handling system that emphasizes context accumulation, structured diagnostics, and flexible formatting. Built around the AnyError type, it allows you to wrap any error with rich metadata and progressively add context as errors bubble up through your application.
Core Ideas
AnyError— The main error container that wraps anyErrortype with context chainsLuhTwin<T>— Type alias forResult<T, AnyError>, the primary result typeErrorContext— Structured metadata including messages, file/line info, and custom argumentsWrap— Wrapping existing Results into LuhTwinTwin— Transforming existing Results into LuhTwinEncase— Encase existing LuhTwins in another layer of context
Quick Start
Add luhtwin to your Cargo.toml:
[]
= "0.1.4"
Example
use ;
use fs;
Error Output
When an error occurs, luhtwin provides detailed, layered context:
LUHTWIN_FULL=1 to see full errors <3
1: failed to read config from config.json: No such file or directory
2: failed to parse config as JSON
3: config loading failed
source: No such file or directory (os error 2)
backtrace:
disabled backtrace
With LUHTWIN_FULL=1, you get full context including file/line info and attached arguments.
Common Patterns
Converting foreign errors with .twin()
use File;
Wrapping errors with context using .wrap()
Adding layers with .encase()
Using the at! macro for rich context
Environment Variables
LUHTWIN_FULL=1- Show full error details with all attached argumentsRUST_BACKTRACE=1- Enable backtrace capture (standard Rust behavior)
Documentation
For full documentation, see docs.rs/luhtwin.
made with love - s.c