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
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
- Define all possible error structs in a
#[skerry_mod]. - Mark functions with
#[skerry_fn]. - 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 *; // Recommended to be pub for easier macro expansions
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 #[skerry_fn], 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
Using Skerry inside Impl Blocks
Skerry provides the #[skerry_impl] attribute to handle methods within impl blocks.
This attribute coordinates with #[skerry_fn] to split the generated code:
- Top-Level: The error enums are generated outside the
implblock. - Method-Level: The method signature is updated, and all
?operators are automatically transformed to wrap errors intoGlobalErrors.
Example
use *;
#
;
// Optional prefix for functions inside impl block
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.
License: MIT