Easy Macros
Automatic error context for any Rust project + powerful procedural macro utilities.
General feature flags
# Only automatic error context
[]
= { = "...", = ["general"] }
# All tools
[]
= { = "...", = ["for-macro"] }
Features
1. Automatic Error Context - Works in Any Project
Add .with_context() to all ? operators automatically:
use always_context;
use Result;
Control attributes: #[no_context], #[context(display)], #[context(ignore)]
2. Attribute Pattern Matching
Extract values from attributes using __unknown__ placeholder:
use ;
// Extract from type attributes
let routes: = get_attributes!;
// Extract from field attributes
let methods: =
fields_get_attributes!;
// Partial identifier matching
let tests: = get_attributes!;
// Matches: #[test_case_one], #[test_case_two], etc.
Check attributes: has_attributes!(input, #[derive(Debug)] #[serde(...)])
Filter fields: fields_with_attributes!(input, #[validate])
3. Exhaustive AST Traversal
Generate recursive handlers for all syn types:
use all_syntax_cases;
all_syntax_cases!
Smart unwrapping of Box<T>, Vec<T>, Punctuated<T, _>. Generates handlers for Item, Expr, Stmt, Pat, Type, and more.
4. Helper Utilities
use *;
// Manual error context with file/line info
read.with_context?;
// Token stream builder
let mut tokens = default;
tokens.add;
tokens.braced; // Wrap in { }
// Parse with compile_error! on failure
let parsed = parse_macro_input!;
// Generate indexed names: field0, field1, field2
let names = indexed_name;
// Find crates (handles renames)
let path = find_crate?;
let async_rt = find_crate_list?;
5. Result Type for Proc Macros
Use anyhow::Result<TokenStream> in proc macros:
use anyhow_result;
// Errors convert to compile_error! automatically
Complete Example
use ;
Feature Flags
general- Error context (#[always_context],context!) for any projectfor-macro- All tools for proc-macro development (includesgeneral)build- Build macro that auto-adds#[always_context]to all functions returninganyhow::Resulteasy-sql- Add Easy-Sql crate integration for#[always_context]and attribute macros
License
Apache License, Version 2.0 - See LICENSE