#code #generator #codegen #gencode

codespawn

C++ and Rust code generator. Supports XML and JSON for API definitions.

13 releases

Uses old Rust 2015

0.3.3 May 8, 2017
0.3.2 Aug 31, 2016
0.3.0 Jul 26, 2016
0.2.1 Jul 22, 2016
0.0.1 Jun 24, 2016

#2414 in Rust patterns

Download history 8/week @ 2023-11-02 2/week @ 2023-11-09 3/week @ 2023-11-16 14/week @ 2023-11-23 69/week @ 2023-11-30 1/week @ 2023-12-07 16/week @ 2023-12-14 27/week @ 2023-12-21 13/week @ 2023-12-28 1/week @ 2024-01-04 2/week @ 2024-01-11 23/week @ 2024-01-18 27/week @ 2024-01-25 27/week @ 2024-02-01 30/week @ 2024-02-08 149/week @ 2024-02-15

233 downloads per month

MIT/Apache

52KB
1K SLoC

Codespawn

Crates.io Documentation Build Status Build status Coverage Status

Codespawn is a basic C++ and Rust code generator. Desired API can be defined using either JSON or XML and the crate supports both reading from a file or a string. Currently it's possible to generate enums, structs, functions, function pointers, variables and bitflags with all applicable attributes and properties.

This crate was created as a helper tool for ProDBG. See example XML for instructions on how to construct the API definition.

Documentation

Usage

# Cargo.toml
[dependencies]
codespawn = "0.3"

Example

extern crate codespawn;

fn main()
{
    // generate from XML definition
    let raw_code = codespawn::from_xml("examples/sample.xml").unwrap();
    // generate from JSON definition
    //let raw_code = codespawn::from_json("examples/sample.json").unwrap();

    // generate code, store as String
    let cpp_code  = raw_code.to_cpp().unwrap().to_string();
    let rust_code = raw_code.to_rust().unwrap().to_string();

    // generate and save directly to file
    raw_code.to_cpp().unwrap().to_file("sample.cpp");
    raw_code.to_rust().unwrap().to_file("sample.rs");
}

Build instructions

cargo build
cargo run --example xml
cargo run --example json

This will run the example which will generate code and save it to files using sample XML definition.

License

Licensed under either of

Dependencies

~535KB
~11K SLoC