6 releases

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

#496 in Rust patterns

Download history 7642/week @ 2024-01-05 6676/week @ 2024-01-12 9681/week @ 2024-01-19 8666/week @ 2024-01-26 7789/week @ 2024-02-02 7051/week @ 2024-02-09 8992/week @ 2024-02-16 11182/week @ 2024-02-23 12446/week @ 2024-03-01 9783/week @ 2024-03-08 8072/week @ 2024-03-15 7929/week @ 2024-03-22 10308/week @ 2024-03-29 8994/week @ 2024-04-05 9656/week @ 2024-04-12 10836/week @ 2024-04-19

41,236 downloads per month
Used in 48 crates (33 directly)

MIT license

68KB
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

~1MB
~16K SLoC