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

Defines a code block. This is used to define a function body.

Implementations

Returns an empty code block.

Arguments
  • before - The contents to add before the block. This can be an empty “” if you don’t want anything before the block.
Examples
use rust_codegen::Block;
 
let mut block = Block::new("");

Push a line to the code block.

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

Push a nested block to this block.

Arguments
  • block - The block to push to this block.
Examples
use rust_codegen::Block;
 
let mut block_1 = Block::new("");
block_1.line("println!(\"Hello, world!\");");
 
let mut block_2 = Block::new("");
block_2.line("println!(\"from Rust!!\");");
 
block_1.push_block(block_2);

Add a snippet after the block.

Arguments
  • after - The snippet to add after the code block.
Examples
use rust_codegen::Block;
 
let mut block = Block::new("This is before");
block.after("This is after");

Formats the block using the given formatter.

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