6 releases

Uses new Rust 2021

0.2.0 Sep 19, 2022
0.1.3 May 9, 2020
0.1.1 Mar 15, 2019
0.1.0 Nov 10, 2018
0.0.0 Oct 31, 2017

#183 in Rust patterns

Download history 1263/week @ 2022-08-19 1302/week @ 2022-08-26 1555/week @ 2022-09-02 2023/week @ 2022-09-09 1718/week @ 2022-09-16 2088/week @ 2022-09-23 1684/week @ 2022-09-30 1594/week @ 2022-10-07 1558/week @ 2022-10-14 1852/week @ 2022-10-21 4583/week @ 2022-10-28 3608/week @ 2022-11-04 4013/week @ 2022-11-11 3391/week @ 2022-11-18 2713/week @ 2022-11-25 4034/week @ 2022-12-02

14,665 downloads per month
Used in 36 crates (26 directly)

MIT license

67KB
2K SLoC

Codegen

Provides an builder API to assist in generating Rust code.

More information about this crate can be found in the crate documentation

Installation

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

[dependencies]
codegen = "0.2.0"

Next, add this to your crate:

extern crate codegen;

Usage

  1. Create a Scope instance.
  2. Use the builder API to add elements to the scope.
  3. Call Scope::to_string() to get the generated code.

For example:

use codegen::Scope;

let mut scope = Scope::new();

scope.new_struct("Foo")
    .derive("Debug")
    .field("one", "usize")
    .field("two", "String");

println!("{}", scope.to_string());

Non-goals

codegen will not attempt to perform anything beyond basic formatting. For improved formatting, the generated code can be passed to rustfmt.

License

This project is licensed under the MIT license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in codegen by you, shall be licensed as MIT, without any additional terms or conditions.

Dependencies

~420–570KB
~10K SLoC