Derive macros for rsActor framework
This crate provides derive macros for the rsActor framework, allowing users to automatically implement common traits with sensible defaults.
Actor Derive Macro
The #[derive(Actor)] macro provides a convenient way to implement the Actor trait
for simple structs and enums that don't require complex initialization logic.
Generated Implementation
When you use #[derive(Actor)], it generates:
Argstype set toSelf(the struct or enum itself)Errortype set tostd::convert::Infallible(never fails)on_startmethod that simply returns the provided args
Usage
With Structs
use Actor;
With Enums
use Actor;
This is equivalent to manually writing:
#
use ;
use Infallible;
When to Use
Use the derive macro when:
- Your actor doesn't need complex initialization
- You want to pass a fully constructed instance to
spawn() - You don't need custom error handling during initialization
For complex initialization (async resource setup, validation, etc.), implement the Actor trait manually.
Message Handlers Attribute Macro
The #[message_handlers] attribute macro combined with #[handler] method attributes
provides an automated way to generate Message trait implementations and register message handlers.
Usage
use ;
;
;
Benefits
- Automatic generation of
Message<T>trait implementations - Selective processing: only methods with
#[handler]attribute are processed - Reduced boilerplate and potential for errors
- Type-safe message handling with compile-time checks