Skip to content

A Rust library providing a builder API to generate Rust code.

License

Notifications You must be signed in to change notification settings

joshcoden/codegen

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Codegen

Provides an builder API to assist in generating Rust code.

Build Status

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 = { git = "https://github.com/carllerche/codegen" } # Soon on crates.io

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.

About

A Rust library providing a builder API to generate Rust code.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 100.0%