Struct wasm_encoder::NameSection

source ·
pub struct NameSection { /* private fields */ }
Expand description

An encoder for the custom name section.

§Example

use wasm_encoder::{Module, NameSection, NameMap};

let mut names = NameSection::new();
names.module("the module name");

let mut function_names = NameMap::new();
function_names.append(0, "name of function 0");
function_names.append(1, "a better function");
function_names.append(3, "the best function");
names.functions(&function_names);

let mut module = Module::new();
module.section(&names);

let wasm_bytes = module.finish();

Implementations§

source§

impl NameSection

source

pub fn new() -> Self

Creates a new blank name custom section.

source

pub fn module(&mut self, name: &str)

Appends a module name subsection to this section.

This will indicate that the name of the entire module should be the name specified. Note that this should be encoded first before other subsections.

source

pub fn functions(&mut self, names: &NameMap)

Appends a subsection for the names of all functions in this wasm module.

Function names are declared in the names map provided where the index in the map corresponds to the wasm index of the function. This section should come after the module name subsection (if present) and before the locals subsection (if present).

source

pub fn locals(&mut self, names: &IndirectNameMap)

Appends a subsection for the names of locals within functions in this wasm module.

This section should come after the function name subsection (if present) and before the labels subsection (if present).

source

pub fn labels(&mut self, names: &IndirectNameMap)

Appends a subsection for the names of labels within functions in this wasm module.

This section should come after the local name subsection (if present) and before the type subsection (if present).

source

pub fn types(&mut self, names: &NameMap)

Appends a subsection for the names of all types in this wasm module.

This section should come after the label name subsection (if present) and before the table subsection (if present).

source

pub fn tables(&mut self, names: &NameMap)

Appends a subsection for the names of all tables in this wasm module.

This section should come after the type name subsection (if present) and before the memory subsection (if present).

source

pub fn memories(&mut self, names: &NameMap)

Appends a subsection for the names of all memories in this wasm module.

This section should come after the table name subsection (if present) and before the global subsection (if present).

source

pub fn globals(&mut self, names: &NameMap)

Appends a subsection for the names of all globals in this wasm module.

This section should come after the memory name subsection (if present) and before the element subsection (if present).

source

pub fn elements(&mut self, names: &NameMap)

Appends a subsection for the names of all elements in this wasm module.

This section should come after the global name subsection (if present) and before the data subsection (if present).

source

pub fn data(&mut self, names: &NameMap)

Appends a subsection for the names of all data in this wasm module.

This section should come after the element name subsection (if present) and before the field subsection (if present).

source

pub fn tag(&mut self, names: &NameMap)

Appends a subsection for the names of all tags in this wasm module.

This section should come after the data name subsection (if present).

source

pub fn fields(&mut self, names: &IndirectNameMap)

Appends a subsection for the names of fields within types in this wasm module.

This section should come after the data name subsection (if present) and before the tag subsection (if present).

source

pub fn tags(&mut self, names: &NameMap)

Appends a subsection for the names of all tags in this wasm module.

This section should come after the field name subsection (if present).

source

pub fn as_custom<'a>(&'a self) -> CustomSection<'a>

View the encoded section as a CustomSection.

Trait Implementations§

source§

impl Clone for NameSection

source§

fn clone(&self) -> NameSection

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for NameSection

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for NameSection

source§

fn default() -> NameSection

Returns the “default value” for a type. Read more
source§

impl Encode for NameSection

source§

fn encode(&self, sink: &mut Vec<u8>)

Encode the type into the given byte sink.
source§

impl Section for NameSection

source§

fn id(&self) -> u8

Gets the section identifier for this section.
source§

fn append_to(&self, dst: &mut Vec<u8>)

Appends this section to the specified destination list of bytes.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.