ResExt - anyhow-like error-handling with thiserror-like performance

⚓ Rust    📅 2026-02-12    👤 surdeus    👁️ 1      

surdeus

I’ve always loved the ergonomics of anyhow, but I often found myself using thiserror in performance-critical paths or no_std environments because I didn't want to force a heap allocation for every single error context.
So, I built ResExt

What is it?

It’s a proc-macro-powered error handling library that gives you the .context() and bail! ergonomics you're used to, but keeps your error messages on the stack by default.

The core idea: Hybrid Spilling

The core idea is a hybrid buffer. You define your error enum with the #[resext] attribute:

#[resext(buf_size = 64, alloc = true)]
pub enum MyError {
    Io(std::io::Error),
    Config(String),
}
  • Small Contexts: If your message is under 64 bytes, it lives entirely on the stack. No Box, no String, zero allocation.
  • Large Contexts: If you exceed the buffer, it gracefully spills to the heap (using a Vec to avoid redundant UTF-8 checks).
  • No-Std Friendly: You can toggle std and alloc per-enum. In a pure no_std environment without an allocator, it just gracefully truncates with a "..." marker.

I’d love to get some feedback on the architecture
Check it out here: GitHub repo

1 post - 1 participant

Read full topic

🏷️ Rust_feed