[][src]Struct wasm_encoder::Function

pub struct Function { /* fields omitted */ }

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

impl Function[src]

pub fn new<L>(locals: L) -> Self where
    L: IntoIterator<Item = (u32, ValType)>,
    L::IntoIter: ExactSizeIterator
[src]

Create a new function body with the given locals.

pub fn instruction(&mut self, instruction: Instruction<'_>) -> &mut Self[src]

Write an instruction into this function body.

pub fn raw<B>(&mut self, bytes: B) -> &mut Self where
    B: IntoIterator<Item = u8>, 
[src]

Add raw bytes to this function's body.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.