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

Defines a trait.

Implementations

Return a trait definition with the provided name.

Arguments
  • name - The name of the trait.
Examples
use rust_codegen::Trait;
 
let foo_trait = Trait::new("Foo");

Returns a reference to the type.

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

Set the trait visibility.

Arguments
  • vis - The visibility to set for the trait.
Examples
use rust_codegen::Trait;
 
let mut foo_trait = Trait::new("Foo");
foo_trait.vis("pub");

Add a generic to the trait.

Examples
use rust_codegen::Trait;
 
let mut foo_trait = Trait::new("Foo");
foo_trait.generic("T");

Add a where bound to the trait.

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

Add a macro to the trait def (e.g. "#[async_trait]").

Arguments
  • r#macro - The macro to add.
Examples
use rust_codegen::Trait;
 
let mut foo_trait = Trait::new("Foo");
foo_trait.r#macro("async_trait");

Add a parent trait.

Arguments
  • ty - The type of the parent trait.
Examples
use rust_codegen::Trait;
 
let mut foo_trait = Trait::new("Foo");
foo_trait.parent("Bar");

Set the trait documentation.

Arguments
  • docs - The documentation for the trait.
Examples
use rust_codegen::Trait;
 
let mut foo_trait = Trait::new("Foo");
foo_trait.doc("Sample trait documentation.");

Add an associated type. Returns a mutable reference to the new associated type for futher configuration.

Arguments
  • name - The name of the associated type.
Examples
use rust_codegen::Trait;
 
let mut foo_trait = Trait::new("Foo");
foo_trait.associated_type("A");

Push a new function definition, returning a mutable reference to it.

Arguments
  • name - The name of the function.
Examples
use rust_codegen::Trait;
 
let mut foo_trait = Trait::new("Foo");
foo_trait.new_fn("bar_fn");

Push a function definition.

Arguments
  • item - The function to add.
Examples
use rust_codegen::{Function,Trait};
 
let mut foo_trait = Trait::new("Foo");
let mut bar_fn = Function::new("bar_fn");
 
foo_trait.push_fn(bar_fn);

Formats the scope using the given formatter.

Arguments
  • fmt - The formatter to use.
Examples
use rust_codegen::{Formatter,Trait};
 
let mut dest = String::new();
let mut fmt = Formatter::new(&mut dest);
 
let mut foo_trait = Trait::new("Foo");
foo_trait.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.