pub struct Enum { /* private fields */ }
Expand description

Defines an enumeration.

Implementations

Returns a enum definition with the provided name.

Arguments
  • name - The name of the enum.
Examples
use rust_codegen::Enum;
 
let foo_enum = Enum::new("Foo");

Returns a reference to the enum’s type.

Examples
use rust_codegen::Enum;
 
let foo_enum = Enum::new("Foo");
println!("{:?}", foo_enum.ty());

Set the enum’s visibility.

Arguments
  • vis - The visibility of the enum.
Examples
use rust_codegen::Enum;
 
let mut foo_enum = Enum::new("Foo");
foo_enum.vis("pub");

Add a generic to the enum.

Arguments
  • name - The name of the generic.
Examples
use rust_codegen::Enum;
 
let mut foo_enum = Enum::new("Foo");
foo_enum.generic("T");

Add a where bound to the enum.

Arguments
  • name - The name of the bound.
  • ty - The type of the bound.
Examples
use rust_codegen::Enum;
 
let mut foo_enum = Enum::new("Foo");
foo_enum.bound("T", "Default");

Set the enum’s documentation.

Arguments
  • docs - The docs to set for the enum.
Examples
use rust_codegen::Enum;
 
let mut foo_enum = Enum::new("Foo");
foo_enum.doc("Sample Foo enum documentation");

Add a new type that the enum should derive.

Arguments
  • name - The name of the derive.
Examples
use rust_codegen::Enum;
 
let mut foo_enum = Enum::new("Foo");
foo_enum.derive("Debug");

Specify lint attribute to supress a warning or error.

Arguments
  • allow - The lint attribute to apply.
Examples
use rust_codegen::Enum;
 
let mut foo_enum = Enum::new("Foo");
foo_enum.allow("dead_code");

Specify representation.

Arguments
  • repr - The representation to specify.
Examples
use rust_codegen::Enum;
 
let mut foo_enum = Enum::new("Foo");
foo_enum.repr("C");

Push a variant to the enum, returning a mutable reference to it.

Arguments
  • name - The name of the variant.
Examples
use rust_codegen::Enum;
 
let mut foo_enum = Enum::new("Foo");
foo_enum.new_variant("FirstVariant");

Push a variant to the enum.

Arguments
  • item - The variant to push to the enum.
Examples
use rust_codegen::*;
 
let mut foo_enum = Enum::new("Foo");
 
let foo_enum_first_variant = Variant::new("FirstVariant");
foo_enum.push_variant(foo_enum_first_variant);

Formats the enum using the given formatter.

Arguments
  • fmt - The formatter to use.
Examples
use rust_codegen::*;
 
let mut dest = String::new();
let mut fmt = Formatter::new(&mut dest);
 
let foo_enum = Enum::new("Foo");
foo_enum.fmt(&mut fmt);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.