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

Defines an impl block.

Implementations

Returns a new impl definition.

Arguments
  • target - The impl’s target.
Examples
use rust_codegen::Impl;
 
let foo_impl = Impl::new("Foo");

Add a generic to the impl block.

This adds the generic for the block (impl<T>) and not the target type.

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

Add a generic to the target type.

Arguments
  • ty - The generic type to add to the target.
Examples
use rust_codegen::Impl;
 
let mut foo_impl = Impl::new("Foo");
foo_impl.target_generic("T");

Set the trait that the impl block is implementing.

Arguments
  • ty - The trait that the impl block is implementing.
Examples
use rust_codegen::Impl;
 
let mut foo_impl = Impl::new("Foo");
foo_impl.impl_trait("T");

Add a macro to the impl block (e.g. "#[async_trait]")

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

Set an associated type.

Arguments
  • name - The name of the associated type.
  • ty - The type of the associated type.
Examples
use rust_codegen::*;
 
let mut scope = Scope::new();
 
let trait_foo = scope.new_trait("Foo");
let mut impl_bar = Impl::new("Bar");
 
impl_bar.associate_type("A", "Foo");

Add a where bound to the impl block.

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

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

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

Push a function definition.

Arguments
  • item - The function definition to push.
Examples
use rust_codegen::{Function,Impl};
 
let mut foo_impl = Impl::new("Foo");
let bar_fn = Function::new("bar");
 
foo_impl.push_fn(bar_fn);

Formats the impl block 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_impl = Impl::new("Foo");
foo_impl.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.