Struct parity_wasm::elements::Module
source · pub struct Module { /* private fields */ }
Expand description
WebAssembly module
Implementations§
source§impl Module
impl Module
sourcepub fn from_bytes<T: AsRef<[u8]>>(input: T) -> Result<Self, Error>
pub fn from_bytes<T: AsRef<[u8]>>(input: T) -> Result<Self, Error>
Construct a module from a slice.
sourcepub fn into_sections(self) -> Vec<Section>
pub fn into_sections(self) -> Vec<Section>
Destructure the module, yielding sections
sourcepub fn sections(&self) -> &[Section]
pub fn sections(&self) -> &[Section]
Sections list.
Each known section is optional and may appear at most once.
sourcepub fn sections_mut(&mut self) -> &mut Vec<Section>
pub fn sections_mut(&mut self) -> &mut Vec<Section>
Sections list (mutable).
Each known section is optional and may appear at most once.
sourcepub fn insert_section(&mut self, section: Section) -> Result<(), Error>
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.
sourcepub fn code_section(&self) -> Option<&CodeSection>
pub fn code_section(&self) -> Option<&CodeSection>
Code section reference, if any.
sourcepub fn code_section_mut(&mut self) -> Option<&mut CodeSection>
pub fn code_section_mut(&mut self) -> Option<&mut CodeSection>
Code section mutable reference, if any.
sourcepub fn type_section(&self) -> Option<&TypeSection>
pub fn type_section(&self) -> Option<&TypeSection>
Types section reference, if any.
sourcepub fn type_section_mut(&mut self) -> Option<&mut TypeSection>
pub fn type_section_mut(&mut self) -> Option<&mut TypeSection>
Types section mutable reference, if any.
sourcepub fn import_section(&self) -> Option<&ImportSection>
pub fn import_section(&self) -> Option<&ImportSection>
Imports section reference, if any.
sourcepub fn import_section_mut(&mut self) -> Option<&mut ImportSection>
pub fn import_section_mut(&mut self) -> Option<&mut ImportSection>
Imports section mutable reference, if any.
sourcepub fn global_section(&self) -> Option<&GlobalSection>
pub fn global_section(&self) -> Option<&GlobalSection>
Globals section reference, if any.
sourcepub fn global_section_mut(&mut self) -> Option<&mut GlobalSection>
pub fn global_section_mut(&mut self) -> Option<&mut GlobalSection>
Globals section mutable reference, if any.
sourcepub fn export_section(&self) -> Option<&ExportSection>
pub fn export_section(&self) -> Option<&ExportSection>
Exports section reference, if any.
sourcepub fn export_section_mut(&mut self) -> Option<&mut ExportSection>
pub fn export_section_mut(&mut self) -> Option<&mut ExportSection>
Exports section mutable reference, if any.
sourcepub fn table_section(&self) -> Option<&TableSection>
pub fn table_section(&self) -> Option<&TableSection>
Table section reference, if any.
sourcepub fn table_section_mut(&mut self) -> Option<&mut TableSection>
pub fn table_section_mut(&mut self) -> Option<&mut TableSection>
Table section mutable reference, if any.
sourcepub fn data_section(&self) -> Option<&DataSection>
pub fn data_section(&self) -> Option<&DataSection>
Data section reference, if any.
sourcepub fn data_section_mut(&mut self) -> Option<&mut DataSection>
pub fn data_section_mut(&mut self) -> Option<&mut DataSection>
Data section mutable reference, if any.
sourcepub fn elements_section(&self) -> Option<&ElementSection>
pub fn elements_section(&self) -> Option<&ElementSection>
Element section reference, if any.
sourcepub fn elements_section_mut(&mut self) -> Option<&mut ElementSection>
pub fn elements_section_mut(&mut self) -> Option<&mut ElementSection>
Element section mutable reference, if any.
sourcepub fn memory_section(&self) -> Option<&MemorySection>
pub fn memory_section(&self) -> Option<&MemorySection>
Memory section reference, if any.
sourcepub fn memory_section_mut(&mut self) -> Option<&mut MemorySection>
pub fn memory_section_mut(&mut self) -> Option<&mut MemorySection>
Memory section mutable reference, if any.
sourcepub fn function_section(&self) -> Option<&FunctionSection>
pub fn function_section(&self) -> Option<&FunctionSection>
Functions signatures section reference, if any.
sourcepub fn function_section_mut(&mut self) -> Option<&mut FunctionSection>
pub fn function_section_mut(&mut self) -> Option<&mut FunctionSection>
Functions signatures section mutable reference, if any.
sourcepub fn start_section(&self) -> Option<u32>
pub fn start_section(&self) -> Option<u32>
Start section, if any.
sourcepub fn set_start_section(&mut self, new_start: u32)
pub fn set_start_section(&mut self, new_start: u32)
Changes the module’s start section.
sourcepub fn clear_start_section(&mut self)
pub fn clear_start_section(&mut self)
Removes the module’s start section.
sourcepub fn custom_sections(&self) -> impl Iterator<Item = &CustomSection>
pub fn custom_sections(&self) -> impl Iterator<Item = &CustomSection>
Returns an iterator over the module’s custom sections
sourcepub fn set_custom_section(&mut self, name: impl Into<String>, payload: Vec<u8>)
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.
sourcepub fn clear_custom_section(
&mut self,
name: impl AsRef<str>
) -> Option<CustomSection>
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.
sourcepub fn has_names_section(&self) -> bool
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
sourcepub fn names_section(&self) -> Option<&NameSection>
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
sourcepub fn names_section_mut(&mut self) -> Option<&mut NameSection>
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
sourcepub fn parse_names(self) -> Result<Self, (Vec<(usize, Error)>, Self)>
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.
sourcepub fn parse_reloc(self) -> Result<Self, (Vec<(usize, Error)>, Self)>
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.
sourcepub fn import_count(&self, count_type: ImportCountType) -> usize
pub fn import_count(&self, count_type: ImportCountType) -> usize
Count imports by provided type.
sourcepub fn functions_space(&self) -> usize
pub fn functions_space(&self) -> usize
Query functions space.
sourcepub fn globals_space(&self) -> usize
pub fn globals_space(&self) -> usize
Query globals space.
sourcepub fn table_space(&self) -> usize
pub fn table_space(&self) -> usize
Query table space.
sourcepub fn memory_space(&self) -> usize
pub fn memory_space(&self) -> usize
Query memory space.