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

Defines a struct.

Implementations

Return a structure definition with the provided name.

Arguments
  • name - The name of the struct.
Examples
use rust_codegen::Struct;
 
let foo_struct = Struct::new("Foo");

Returns a reference to the type.

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

Set the structure visibility.

Arguments
  • vis - The visibility of the struct.
Examples
use rust_codegen::Struct;
 
let mut foo_struct = Struct::new("Foo");
foo_struct.vis("pub");

Add a generic to the struct.

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

Add a where bound to the struct.

Arguments
  • name - The name of the bound.
  • ty - The type of the bound.
Examples
use rust_codegen::Struct;
 
let mut foo_struct = Struct::new("Foo");
foo_struct.bound("A", "TraitA");

Set the structure documentation.

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

Add a new type that the struct should derive.

Arguments
  • name - The name of the type to derive.
Examples
use rust_codegen::Struct;
 
let mut foo_struct = Struct::new("Foo");
foo_struct.derive("Debug");

Specify lint attribute to supress a warning or error.

Arguments
  • allow - The lint attribute to add.
Examples
use rust_codegen::Struct;
 
let mut foo_struct = Struct::new("Foo");
foo_struct.allow("dead_code");

Specify representation.

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

Push a named field to the struct.

A struct can either set named fields with this function or tuple fields with push_tuple_field, but not both.

Arguments
  • field - The named field to push.
Examples
use rust_codegen::{Field,Struct};
 
let mut foo_struct = Struct::new("Foo");
let mut bar_field = Field::new("bar", "i32");
 
foo_struct.push_field(bar_field);

Add a named field to the struct.

A struct can either set named fields with this function or tuple fields with tuple_field, but not both.

Arguments
  • name - The name of the field.
  • ty - The type of the field.
Examples
use rust_codegen::Struct;
 
let mut foo_struct = Struct::new("Foo");
foo_struct.field("bar", "i32");

Add a tuple field to the struct.

A struct can either set tuple fields with this function or named fields with field, but not both.

Arguments
  • ty - The type of the tuple field to add.
Examples
use rust_codegen::{Struct,Type};
 
let mut foo_struct = Struct::new("Foo");
let mut bar_type = Type::new("bar");
 
foo_struct.tuple_field(bar_type);

Adds an attribute to the struct (e.g. "#[some_attribute]")

Arguments
  • attribute - The attribute to add.
Examples
use rust_codegen::Struct;
 
let mut foo_struct = Struct::new("Foo");
foo_struct.attr("some_attribute");

Formats the struct 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 mut foo_struct = Struct::new("Foo");
foo_struct.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.