pub struct Function {
    pub body: Option<Vec<Body>>,
    /* private fields */
}
Expand description

Defines a function.

Fields

body: Option<Vec<Body>>

Body contents.

Implementations

Return a new function definition.

Arguments
  • name - The name of the function.
Examples
use rust_codegen::Function;
 
let foo_fn = Function::new("foo_fn");

Set the function documentation.

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

Specify lint attribute to supress a warning or error.

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

Set the function visibility.

Arguments
  • vis - The visiblity to set for the function.
Examples
use rust_codegen::Function;
 
let mut foo_fn = Function::new("foo_fn");
foo_fn.vis("pub");

Set whether this function is async or not.

Arguments
  • async - Indicates whether this function is async or not.
Examples
use rust_codegen::Function;
 
let mut foo_fn = Function::new("foo_fn");
foo_fn.set_async(true);

Add a generic to the function.

Arguments
  • name - The name of the generic to add.
Examples
use rust_codegen::Function;
 
let mut foo_fn = Function::new("foo_fn");
foo_fn.generic("T");

Add self as a function argument.

Examples
use rust_codegen::Function;
 
let mut foo_fn = Function::new("foo_fn");
foo_fn.arg_self();

Add &self as a function argument.

Examples
use rust_codegen::Function;
 
let mut foo_fn = Function::new("foo_fn");
foo_fn.arg_ref_self();

Add &mut self as a function argument.

Examples
use rust_codegen::Function;
 
let mut foo_fn = Function::new("foo_fn");
foo_fn.arg_mut_self();

Add a function argument.

Arguments
  • name - The name of the argument.
  • ty - The type of the argument.
Examples
use rust_codegen::Function;
 
let mut foo_fn = Function::new("foo_fn");
foo_fn.arg("name", "&str");

Set the function return type.

Arguments
  • ty - The return type.
Examples
use rust_codegen::Function;
 
let mut foo_fn = Function::new("foo_fn");
foo_fn.ret("String");

Add a where bound to the function.

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

Push a line to the function implementation.

Arguments
  • line - The line to add to the function.
Examples
use rust_codegen::Function;
 
let mut foo_fn = Function::new("foo_fn");
foo_fn.line("println!(\"Hello, world!\")");

Add an attribute to the function.

Arguments
  • attribute - The attribute to add.
Examples
use rust_codegen::Function;

let mut foo_fn = Function::new("foo_fn");
foo_fn.attr("test");

Specify an extern ABI for the function.

Arguments
  • abi - The extern ABI to add.
Examples
use rust_codegen::Function;

let mut foo_fn = Function::new("foo_fn");
foo_fn.extern_abi("C");

Push a block to the function implementation.

Arguments
  • block - The block to push to the function.
Examples
use rust_codegen::*;

let mut foo_fn = Function::new("foo_fn");
 
let mut block = Block::new("");
block.line("println!(\"Hello, world!\");");
 
foo_fn.push_block(block);

Formats the function using the given formatter.

Arguments
  • is_trait - Indicates whether it is a trait or not.
  • fmt - The formatter to use.
Examples
use rust_codegen::*;
 
let mut dest = String::new();
let mut fmt = Formatter::new(&mut dest);
 
let mut foo_fn = Function::new("foo_fn");
foo_fn.fmt(false, &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.