herolib-derive 0.1.1

Derive macros for herolib-core (ToSchema, ToHeroScript, FromHeroScript)
Documentation

herolib-derive

Crates.io Documentation

Derive macros for herolib-core providing:

  • ToSchema - Generate JSON Schema from Rust structs
  • ToHeroScript - Serialize Rust structs to HeroScript format
  • FromHeroScript - Deserialize HeroScript into Rust structs

Documentation

Installation

This crate is typically used as a dependency of herolib-core. Users should depend on herolib-core which re-exports these macros.

[dependencies]
herolib-core = "0.1"

Building

./build.sh

Usage

The derive macros are re-exported from herolib-core::heroscript:

use herolib_core::heroscript::{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");
// Output:
// !!person.define
//     name:John
//     age:30
//     active:true

// Deserialize from HeroScript
let script = "!!person.define name:Jane age:25 active:false";
let jane = Person::from_heroscript(script).unwrap();

License

Apache-2.0