Crate codegen

Source
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 codegen::Scope;

let mut scope = Scope::new();

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

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

Structs§

AssociatedConst
Defines an associated constant.
AssociatedType
Defines an associated type.
Block
Defines a code block. This is used to define a function body.
Enum
Defines an enumeration.
Field
Defines a struct field.
Formatter
Configures how a scope is formatted.
Function
Defines a function.
Impl
Defines an impl block.
Import
Defines an import (use statement).
Module
Defines a module.
Scope
Defines a scope.
Struct
Defines a struct.
Trait
Define a trait.
Type
Defines a type.
Variant
Defines an enum variant.

Functions§

fmt_bound_rhs
Format multiple generic bounds.
fmt_bounds
Format generic bounds.
fmt_generics
Format generics.