pub struct Impl { /* private fields */ }
Expand description
Returns a new impl definition.
target
- The impl’s target.
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.
name
- The name of the generic.
use rust_codegen::Impl;
let mut foo_impl = Impl::new("Foo");
foo_impl.generic("T");
Add a generic to the target type.
ty
- The generic type to add to the target.
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.
ty
- The trait that the impl block is implementing.
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]"
)
macro
- The macro to add.
use rust_codegen::Impl;
let mut foo_impl = Impl::new("Foo");
foo_impl.r#macro("async_trait");
Set an associated type.
name
- The name of the associated type.
ty
- The type of the associated type.
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.
name
- The name of the bound.
ty
- The type of the bound.
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.
name
- The name of the function.
use rust_codegen::Impl;
let mut foo_impl = Impl::new("Foo");
foo_impl.new_fn("bar_fn");
Push a function definition.
item
- The function definition to push.
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.
fmt
- The formatter to use.
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);
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.