Expand description

Provides a builder API for generating Rust code.

The general strategy for using the crate is as follows:

  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 rust_codegen::Scope;

let mut scope = Scope::new();

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

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

Structs

Defines an associated type.

Defines a code block. This is used to define a function body.

Defines an enumeration.

Defines a struct field.

Configures how a scope is formatted.

Defines a function.

Defines an impl block.

Defines an import (use statement).

Defines a module.

Defines a scope.

Defines a struct.

Defines a trait.

Defines a type.

Defines an enum variant.

Functions

Format multiple generic bounds.

Format generic bounds.

Format generics.