pub struct Trait { /* private fields */ }
Expand description
Return a trait definition with the provided name.
name
- The name of the trait.
use rust_codegen::Trait;
let foo_trait = Trait::new("Foo");
Returns a reference to the type.
use rust_codegen::Trait;
let foo_trait = Trait::new("Foo");
println!("{:?}", foo_trait.ty());
Set the trait visibility.
vis
- The visibility to set for the trait.
use rust_codegen::Trait;
let mut foo_trait = Trait::new("Foo");
foo_trait.vis("pub");
Add a generic to the trait.
use rust_codegen::Trait;
let mut foo_trait = Trait::new("Foo");
foo_trait.generic("T");
Add a where
bound to the trait.
name
- The name of the bound.
ty
- The type of the bound.
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]"
).
r#macro
- The macro to add.
use rust_codegen::Trait;
let mut foo_trait = Trait::new("Foo");
foo_trait.r#macro("async_trait");
Add a parent trait.
ty
- The type of the parent trait.
use rust_codegen::Trait;
let mut foo_trait = Trait::new("Foo");
foo_trait.parent("Bar");
Set the trait documentation.
docs
- The documentation for the trait.
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.
name
- The name of the associated type.
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.
name
- The name of the function.
use rust_codegen::Trait;
let mut foo_trait = Trait::new("Foo");
foo_trait.new_fn("bar_fn");
Push a function definition.
item
- The function to add.
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.
fmt
- The formatter to use.
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);
Performs copy-assignment from source
. Read more
Formats the value using the given formatter. 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.
The type returned in the event of a conversion error.