cgen-rs

Crates.iocgen-rs
lib.rscgen-rs
version0.1.2
sourcesrc
created_at2022-02-09 22:00:54.743447
updated_at2022-02-09 22:08:35.618591
descriptionA library for generating C/C++ code.
homepagehttps://github.com/achreto/cgen-rs
repositoryhttps://github.com/achreto/cgen-rs
max_upload_size
id529907
size149,383
Reto Achermann (achreto)

documentation

https://docs.rs/cgen-rs/

README

CGEN-RS: C/C++ Code Generation from Rust

This crate provides a library with builder API for constructing C/C++ code.

LICENSE

MIT license

CONTRIBUTING

Code contributions are welcome. The submitter must use the sign-off feature for all commits confirming that the submitter has all rights to contribute the code under the license without any additional terms or conditions.

See the AUTHORS file for a list of contributors.

CREDIT

This crate is inspired by codegen-rs`

Installation

To use cgen-rs clone the repository into the lib folder of your Rust project, or use crates.io

Usage

You can use cgen-rs by adding the following lines to Cargo.toml file.

To use codegen-rs, first add this to your Cargo.toml:

[dependencies]
cgen-rs = { path = "lib/cgen-rs" }

Next, create a Scope and use the builder API to create elements in the scope. Lastly, call Scope::to_string() to get formatted C code as a string.

use cgen_rs as CG;

let mut scope = CG::Scope::new();
scope.set_filename("include/my_file.hpp");

scope.push_doc_str("WARNING: This is auto-generated comment\n");
scope.new_include("stdio.h", true);

scope.new_class("MyClass")
    .set_base("StateBase", CG::Visibility::Public)
    .push_attribute(Attribute::new("name", Type::new_int(8)));

println!("{}", scope.to_string());
Commit count: 129

cargo fmt