https://github.com/kondrak/codespawn
Code generator written in Rust
https://github.com/kondrak/codespawn
code-generation codegeneration codegenerator rust
Last synced: 11 months ago
JSON representation
Code generator written in Rust
- Host: GitHub
- URL: https://github.com/kondrak/codespawn
- Owner: kondrak
- License: mit
- Created: 2016-06-23T12:37:45.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-07-11T21:30:13.000Z (over 2 years ago)
- Last Synced: 2025-03-26T10:21:13.020Z (11 months ago)
- Topics: code-generation, codegeneration, codegenerator, rust
- Language: Rust
- Size: 94.7 KB
- Stars: 39
- Watchers: 5
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Codespawn
=========
[](https://crates.io/crates/codespawn)
[](https://docs.rs/codespawn)
[](https://github.com/kondrak/codespawn/actions/workflows/rust.yml)
[](https://coveralls.io/github/kondrak/codespawn?branch=master)

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](https://github.com/emoon/ProDBG). See [example XML](https://github.com/kondrak/codespawn/blob/master/examples/sample.xml) for instructions on how to construct the API definition.
[Documentation](https://docs.rs/codespawn)
Usage
-----
```toml
# Cargo.toml
[dependencies]
codespawn = "0.3"
```
Example
-------
```rust
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](https://github.com/kondrak/codespawn/blob/master/examples/xml.rs) which will generate code and save it to files using sample XML definition.
## License
Licensed under either of
* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)