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

WebAssembly module

Implementations§

source§

impl Module

source

pub fn new(sections: Vec<Section>) -> Self

New module with sections

source

pub fn from_bytes<T: AsRef<[u8]>>(input: T) -> Result<Self, Error>

Construct a module from a slice.

source

pub fn into_bytes(self) -> Result<Vec<u8>, Error>

Serialize a module to a vector.

source

pub fn into_sections(self) -> Vec<Section>

Destructure the module, yielding sections

source

pub fn version(&self) -> u32

Version of module.

source

pub fn sections(&self) -> &[Section]

Sections list.

Each known section is optional and may appear at most once.

source

pub fn sections_mut(&mut self) -> &mut Vec<Section>

Sections list (mutable).

Each known section is optional and may appear at most once.

source

pub fn insert_section(&mut self, section: Section) -> Result<(), Error>

Insert a section, in the correct section ordering. This will fail with an error, if the section can only appear once.

source

pub fn code_section(&self) -> Option<&CodeSection>

Code section reference, if any.

source

pub fn code_section_mut(&mut self) -> Option<&mut CodeSection>

Code section mutable reference, if any.

source

pub fn type_section(&self) -> Option<&TypeSection>

Types section reference, if any.

source

pub fn type_section_mut(&mut self) -> Option<&mut TypeSection>

Types section mutable reference, if any.

source

pub fn import_section(&self) -> Option<&ImportSection>

Imports section reference, if any.

source

pub fn import_section_mut(&mut self) -> Option<&mut ImportSection>

Imports section mutable reference, if any.

source

pub fn global_section(&self) -> Option<&GlobalSection>

Globals section reference, if any.

source

pub fn global_section_mut(&mut self) -> Option<&mut GlobalSection>

Globals section mutable reference, if any.

source

pub fn export_section(&self) -> Option<&ExportSection>

Exports section reference, if any.

source

pub fn export_section_mut(&mut self) -> Option<&mut ExportSection>

Exports section mutable reference, if any.

source

pub fn table_section(&self) -> Option<&TableSection>

Table section reference, if any.

source

pub fn table_section_mut(&mut self) -> Option<&mut TableSection>

Table section mutable reference, if any.

source

pub fn data_section(&self) -> Option<&DataSection>

Data section reference, if any.

source

pub fn data_section_mut(&mut self) -> Option<&mut DataSection>

Data section mutable reference, if any.

source

pub fn elements_section(&self) -> Option<&ElementSection>

Element section reference, if any.

source

pub fn elements_section_mut(&mut self) -> Option<&mut ElementSection>

Element section mutable reference, if any.

source

pub fn memory_section(&self) -> Option<&MemorySection>

Memory section reference, if any.

source

pub fn memory_section_mut(&mut self) -> Option<&mut MemorySection>

Memory section mutable reference, if any.

source

pub fn function_section(&self) -> Option<&FunctionSection>

Functions signatures section reference, if any.

source

pub fn function_section_mut(&mut self) -> Option<&mut FunctionSection>

Functions signatures section mutable reference, if any.

source

pub fn start_section(&self) -> Option<u32>

Start section, if any.

source

pub fn set_start_section(&mut self, new_start: u32)

Changes the module’s start section.

source

pub fn clear_start_section(&mut self)

Removes the module’s start section.

source

pub fn custom_sections(&self) -> impl Iterator<Item = &CustomSection>

Returns an iterator over the module’s custom sections

source

pub fn set_custom_section(&mut self, name: impl Into<String>, payload: Vec<u8>)

Sets the payload associated with the given custom section, or adds a new custom section, as appropriate.

source

pub fn clear_custom_section( &mut self, name: impl AsRef<str> ) -> Option<CustomSection>

Removes the given custom section, if it exists. Returns the removed section if it existed, or None otherwise.

source

pub fn has_names_section(&self) -> bool

True if a name section is present.

NOTE: this can return true even if the section was not parsed, hence names_section() may return None even if this returns true

source

pub fn names_section(&self) -> Option<&NameSection>

Functions signatures section reference, if any.

NOTE: name section is not parsed by default so names_section could return None even if name section exists. Call parse_names to parse name section

source

pub fn names_section_mut(&mut self) -> Option<&mut NameSection>

Functions signatures section mutable reference, if any.

NOTE: name section is not parsed by default so names_section could return None even if name section exists. Call parse_names to parse name section

source

pub fn parse_names(self) -> Result<Self, (Vec<(usize, Error)>, Self)>

Try to parse name section in place.

Corresponding custom section with proper header will convert to name sections If some of them will fail to be decoded, Err variant is returned with the list of (index, Error) tuples of failed sections.

source

pub fn parse_reloc(self) -> Result<Self, (Vec<(usize, Error)>, Self)>

Try to parse reloc section in place.

Corresponding custom section with proper header will convert to reloc sections If some of them will fail to be decoded, Err variant is returned with the list of (index, Error) tuples of failed sections.

source

pub fn import_count(&self, count_type: ImportCountType) -> usize

Count imports by provided type.

source

pub fn functions_space(&self) -> usize

Query functions space.

source

pub fn globals_space(&self) -> usize

Query globals space.

source

pub fn table_space(&self) -> usize

Query table space.

source

pub fn memory_space(&self) -> usize

Query memory space.

Trait Implementations§

source§

impl Clone for Module

source§

fn clone(&self) -> Module

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 Module

source§

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

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

impl Default for Module

source§

fn default() -> Self

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

impl Deserialize for Module

§

type Error = Error

Serialization error produced by deserialization routine.
source§

fn deserialize<R: Read>(reader: &mut R) -> Result<Self, Self::Error>

Deserialize type from serial i/o
source§

impl PartialEq<Module> for Module

source§

fn eq(&self, other: &Module) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Module

§

type Error = Error

Serialization error produced by serialization routine.
source§

fn serialize<W: Write>(self, w: &mut W) -> Result<(), Self::Error>

Serialize type to serial i/o
source§

impl StructuralPartialEq for Module

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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 Twhere 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.