Axin
A Rust procedural macro library for function instrumentation. Axin provides the attribute procedural macro axin that enable clean separation of cross-cutting concerns such as logging, timing, validation, and resource management.
Features
- Entry & Exit Hooks: Execute functions before and after target function execution
- Decorators: Wrap functions with additional behavior using the decorator pattern
- Prologue: Insert statements directly at function entry
- Composable: Combine multiple features seamlessly
- Zero Runtime Cost: All transformations occur at compile time
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Usage
Basic Example
use axin;
Decorators
use axin;
Prologue Statements
use axin;
Combined Usage
use axin;
Execution Order
When combining features, execution follows this order:
- Entry hook
- Decorator
- Prologue statements
- Original function body
- Exit hook
API Reference
Parameters Syntax
prologue(statements...)- Insert statements at function starton_enter(function)- Execute function before main functionon_enter(function_with_args("arg1", "arg2"))- Pass arguments to the entry function
on_exit(function)- Execute function after main functionon_exit(function_with_args("arg1", "arg2"))- Pass arguments to the exit function
decorator(function)- Wrap function with decoratordecorator(function_with_args("arg1", "arg2"))- Pass arguments to the decorator
All parameters are optional and can be combined in any order.
Examples
See the examples/ directory for comprehensive usage examples:
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.