Struct wasm_encoder::Function [−][src]
pub struct Function { /* fields omitted */ }
Expand description
An encoder for a function body within the code section.
Example
use wasm_encoder::{CodeSection, Function, Instruction};
// Define the function body for:
//
// (func (param i32 i32) (result i32)
// local.get 0
// local.get 1
// i32.add)
let locals = vec![];
let mut func = Function::new(locals);
func.instruction(&Instruction::LocalGet(0));
func.instruction(&Instruction::LocalGet(1));
func.instruction(&Instruction::I32Add);
// Add our function to the code section.
let mut code = CodeSection::new();
code.function(&func);
Implementations
pub fn new<L>(locals: L) -> Self where
L: IntoIterator<Item = (u32, ValType)>,
L::IntoIter: ExactSizeIterator,
pub fn new<L>(locals: L) -> Self where
L: IntoIterator<Item = (u32, ValType)>,
L::IntoIter: ExactSizeIterator,
Create a new function body with the given locals.
The argument is an iterator over (N, Ty)
, which defines
that the next N
locals will be of type Ty
.
For example, a function with locals 0 and 1 of type I32 and local 2 of type F32 would be created as:
let f = Function::new([(2, ValType::I32), (1, ValType::F32)]);
For more information about the code section (and function definition) in the WASM binary format see the WebAssembly spec
Create a function from a list of locals’ types.
Unlike Function::new
, this constructor simply takes a list of types
which are in order associated with locals.
For example:
let f = Function::new([(2, ValType::I32), (1, ValType::F32)]);
let g = Function::new_with_locals_types([
ValType::I32, ValType::I32, ValType::F32
]);
assert_eq!(f, g)
Write an instruction into this function body.
Add raw bytes to this function’s body.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Function
impl UnwindSafe for Function
Blanket Implementations
Mutably borrows from an owned value. Read more