herolib-derive
Derive macros for herolib providing:
ToSchema- Generate JSON Schema from Rust structsToHeroScript- Serialize Rust structs to HeroScript formatFromHeroScript- Deserialize HeroScript into Rust structsOsisObject- Implement OSIS database object trait for type-safe storageActor- Define RPC-capable actors with OpenRPC specification generationRpcMethod- Mark methods as RPC endpoints
Documentation
Installation
[]
= "0.1"
Building
Actor System
The Actor system provides a standardized approach for building RPC services with automatic code generation.
Overview
An Actor is a self-contained unit that:
- Encapsulates business logic
- Exposes methods via OpenRPC
- Communicates through Redis queues
- Supports synchronous and asynchronous operations
- Streams logs during execution
Quick Example
use ;
use ;
/// Input for greeting.
/// Output after greeting.
/// Greeter handles greeting operations.
;
Generated Artifacts
For each actor, the macros generate:
| Artifact | Description |
|---|---|
{actor}.openrpc.json |
OpenRPC 1.3 specification |
{actor}_client.rs |
Type-safe async client |
{actor}_handler.rs |
Redis queue handler/server |
{actor}_api.md |
API documentation |
{actor}_api_redis.md |
API documentation with Redis details |
Redis Communication
Actors communicate via Redis queues:
actors:{actor_name}:{instance}:queue # Request queue (List)
actors:{actor_name}:{instance}:result:{id} # Results (String)
actors:{actor_name}:{instance}:logs:{id} # Log stream (List)
Client sends request:
Client reads result:
Documentation
See the docs/ directory for detailed specifications:
- Actor System Architecture
- OpenRPC Generation
- Redis Queue Protocol
- Client Generation
- Handler Generation
- Documentation Generation
- Example Actor
OsisObject Macro
Implement the OsisObject trait for type-safe database storage with automatic SmartID generation:
use OsisObject;
use SmartId;
use ;
// Auto-generated type_name: "user"
// Auto-generated type_name: "user_profile"
// Custom type_name override
Usage with DBTyped:
use DBTyped;
let mut users: = new?;
// Create and store (sid auto-generated)
let mut user = default;
user.name = "Alice".into;
users.set?; // user.sid is now set
// Retrieve by SID
let loaded = users.get?;
HeroScript Macros
ToHeroScript / FromHeroScript
Serialize and deserialize Rust structs to/from HeroScript format:
use ;
// Serialize to HeroScript
let person = Person ;
let hs = person.to_heroscript;
// Output:
// !!person.define
// name:John
// age:30
// active:true
// Deserialize from HeroScript
let script = "!!person.define name:Jane age:25 active:false";
let jane = from_heroscript.unwrap;
ToSchema
Generate JSON Schema from Rust types:
use ToSchema;
// Get JSON Schema
let schema = schema;
License
Apache-2.0