thin-status
Disclaimer: This is a personal project. The views, code, and opinions expressed here are my own and do not represent those of my current or past employers.
A low-overhead, production-grade error status type for Rust, heavily inspired
by Abseil's absl::Status.
It is designed specifically for high-throughput network programming and RPC frameworks where minimizing memory overhead, optimizing cache locality, and eliminating happy-path heap allocations are critical performance requirements.
Features
- Single-Pointer Memory Footprint:
ThinStatusoccupies exactly one pointer word (the size of ausize). Niche optimization guarantees thatOption<ThinStatus>andResult<(), ThinStatus>fit into that same single word without increasing data size. - Zero-Allocation for Inlined Codes: Standard production error
codes matching
ErrorCodethat fit within the tagged pointer boundaries require absolutely zero heap allocation. - Production RPC and gRPC Alignment: Built directly around
canonical RPC status models. Includes out-of-the-box support for
translating standard POSIX
errnocodes (vialibc) and converting to/fromgoogle-cloud-rpcmodels. - Extensible Structured Details: Supports attaching rich,
production-tier diagnostic messages and structured arbitrary
payloads via
google_cloud_wkt::Any(gated under theuse_anyfeature) when an error path demands complex telemetry.
Usage
use ;
use NonZeroI32;
// Zero-allocation status for inline RPC error codes
let status = from_code;
assert_eq!;
// Rich errors (with messages) cleanly fallback to thread-safe heap allocation
let rpc_err = builder
.message
.build;
// Directly maps to native POSIX subsystem failures
if let Some = from_errno