Skerry: Super Kool ERRors Yoh
Example:
use *;
// 1. Define your error boundary
// 2. Generate a 'low_level' error enum automatically
// 3. Use '&' to expand and bubble up sub-errors seamlessly
Known Issues:
- There's no macro for handling
implblocks - Same for
traitblocks
Skerry is a type-safe error management framework designed to kill boilerplate. It allows you to define a global error set while returning granular, function-specific enums that are automatically generated at compile-time.
Core Workflow
- Centralize: Define all possible error structs in a
#[error_module]. - Annotate: Mark functions with
#[fn_error]. - Compose: Use the
&operator to bubble up errors from sub-functions without manually mapping variants.
The Error Module
Every project needs one module (usually errors.rs) that acts as the source of truth.
pub use *; // Required to be pub for macro expansion
Note: When using errors in any other file, import them via crate::errors::*; instead
of individual imports to ensure the macros can resolve the paths correctly.
Function-Specific Enums
By using #[fn_error], you define a return type using a tuple of error structs.
Skerry transforms this into a unique enum named {FunctionName}Error.
The Ampersand (&) Expansion
The & operator is the heart of Skerry. When you put &OtherFnError in your return tuple:
- Expansion: It pulls all variants from
OtherFnErrorinto your current function's list. - Promotion: It allows the
?operator to work seamlessly for that function's return type. - Deduplication: Variants are deduplicated automatically. If
ErrAis added manually and also exists inside a&expansion, only one variant is generated.
The syntax below has the exact same effects, &LowLevelError is nothing more than syntatic sugar
In the cases above the generated enum looks like this
Compile-Time Safety
Skerry uses a custom trait system (MissingConvert) to verify error bounds at
compile-time. If you try to use ? on a function whose errors are not represented
in your current return tuple, the compiler will refuse to build.
Naming and Hygiene
Skerry uses it's own Result enum, replacing the default one this is generated by the
#[error_module] macro. It may not match all functionalities with Rust's std::result::Result.
License: MIT