humblegen 0.3.0

An experimental code-generator in the vain of protobuf, but a little more humble.
Documentation

A humble code generator

humblegen is an experimental code generator written in Rust that allows defining data structures in a custom language and generating declarations as serialization and deserialization implementations in target languages. It is similar to protobuf but focuses on simple uses cases (i.e. small applications) where simplicity trumps performance. Core design goals are:

  • Support Rust and Elm.
  • Use JSON on the wire.
  • As indistinguishable from hand-written serialization code as possible.
  • No runtime library required for the generated code.

Usage

You can compile and install humblegen directly from github:

$ cargo install --git https://github.com/mbr/humblegen-rs

Check out the sample file for an overview of the format. Then just run:

$ humblegen -l rust myfile.humble

As a build dependency

humblegen can be used in your build.rs directly, this has the advantage of automatically recompiling the Rust program whenever the underlying spec changes. To enable, you should first add humblegen to your build dependencies:

[build-dependencies]
humblegen = "*"

(Using cargo add --build via cargo edit is recommended instead)

The, add the following line to build.rs:

humblegen::build("path/to/spec.humble").expect("compile humble");

Finally, import the module (which in this version of humblegen is always in a file called protocol.rs):

mod protocol {
    include!(concat!(env!("OUT_DIR"), "/protocol.rs"));
}