Expand description
§herolib-derive: Derive Macros for herolib
This crate provides procedural macros for herolib:
§Schema & Serialization Macros
- ToSchema - Generate JSON Schema from Rust structs
- ToHeroScript - Serialize Rust structs to HeroScript format
- FromHeroScript - Deserialize HeroScript into Rust structs
§MCP Client Macros
- mcp_client_from_json - Generate typed MCP client from inline JSON spec
- mcp_client_from_file - Generate typed MCP client from JSON file
- mcp_tool - Mark functions as MCP tools
§OpenRPC Client Macros
- openrpc_client! - Generate typed RPC client from OpenRPC specification
§ToSchema Usage
ⓘ
use herolib_derive::ToSchema;
#[derive(ToSchema)]
struct Inner {
value: i32,
}
#[derive(ToSchema)]
struct Outer {
name: String,
inner: Inner,
}
let schema = Outer::json_schema_pretty();
println!("{}", schema);§HeroScript Usage
ⓘ
use herolib_derive::{ToHeroScript, FromHeroScript};
#[derive(ToHeroScript, FromHeroScript, Default)]
struct Person {
name: String,
age: u32,
active: bool,
}
// Serialize to HeroScript
let person = Person { name: "John".into(), age: 30, active: true };
let hs = person.to_heroscript("person", "define");
// Deserialize from HeroScript
let script = "!!person.define name:Jane age:25 active:false";
let jane = Person::from_heroscript(script).unwrap();§OTOML Usage
ⓘ
use herolib_derive::Otoml;
use serde::{Serialize, Deserialize};
#[derive(Otoml, Serialize, Deserialize)]
struct Config {
name: String,
port: u32,
debug: bool,
}
// Serialize to canonical OTOML
let config = Config { name: "server".into(), port: 8080, debug: true };
let otoml = config.dump_otoml().unwrap();
// Deserialize from any valid TOML
let parsed = Config::load_otoml(&otoml).unwrap();Macros§
- mcp_
client_ from_ file - mcp_
client_ from_ json - openrpc_
client - Generate a typed RPC client from an OpenRPC specification.
Attribute Macros§
Derive Macros§
- From
Hero Script - Derive macro for deserializing HeroScript into structs.
- Osis
Object - Derive macro for implementing
OsisObjecttrait. - Otoml
- Derive macro for OTOML serialization/deserialization.
- ToHero
Script - Derive macro for serializing structs to HeroScript format.
- ToSchema
- Derive macro for generating JSON Schema from structs.