codegen

Crates.iocodegen
lib.rscodegen
version0.2.0
sourcesrc
created_at2017-10-31 21:40:00.566384
updated_at2022-09-19 00:04:42.80037
descriptionLibrary for generating Rust code
homepagehttps://github.com/carllerche/codegen
repositoryhttps://github.com/carllerche/codegen
max_upload_size
id37608
size82,260
Iovoslav Iovchev (IovoslavIovchev)

documentation

https://docs.rs/codegen/0.2.0/codegen

README

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.

Commit count: 42

cargo fmt