rstgen 0.1.4

Even simpler code generation for Rust.
Documentation
  • Coverage
  • 100%
    411 out of 411 items documented2 out of 101 items with examples
  • Size
  • Source code size: 217.39 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 30.42 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 15s Average build duration of successful builds.
  • all releases: 15s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • sidneywang

Because origin repo is completely changed, I rename it. It's origin name is GenCo

RsGen is an even simpler code generator for Rust, specifically written for use in reproto.

It does not deal with language-specific syntax, instead it can do some of the basic necessities through specialization.

  • Handle imports, if needed.
  • Quote strings according to language convention.

Examples

This is an example building some JavaScript:

#[macro_use]
extern crate rsgen;

use rsgen::Quoted;

fn main() {
    let mut file: Tokens<JavaScript> = Tokens::new();

    file.push("function foo(v) {");
    file.nested(toks!("return v + ", ", World".quoted(), ";"));
    file.push("}");

    file.push(toks!("foo(", "Hello".quoted(), ");"));

    println!("{}", file.to_string().unwrap());
}

Running this example would print:

function foo(v) {
  return v + ", World";
}
foo("Hello");

Language Support

This section contains example code for some of the supported languages.

For more information, see docs.rs/genco.

Dart

Simple support for importing names.

#[macro_use]
extern crate rsgen;

fn main() {
    use rsgen::dart::imported;

    let m = imported("dart:math").alias("m");
    let sqrt = m.name("sqrt");

    let mut t = toks!();
    t.push("void main() {");
    t.nested({
        let mut body = toks!();
        body.push(toks!("print(", "The Square Root Is:".quoted(), " + ", sqrt, "(42));"));
        body
    });
    t.push("}");
}