pub trait CustomSection:
WalrusAny
+ Debug
+ Send
+ Sync {
// Required methods
fn name(&self) -> &str;
fn data(&self, ids_to_indices: &IdsToIndices) -> Cow<'_, [u8]>;
// Provided methods
fn add_gc_roots(&self, _roots: &mut Roots) { ... }
fn apply_code_transform(&mut self, transform: &CodeTransform) { ... }
}Expand description
A trait for implementing custom sections.
Custom sections are added to a walrus::Module via
my_module.custom_sections.add(my_custom_section).
Required Methods§
Sourcefn name(&self) -> &str
fn name(&self) -> &str
Get this custom section’s name.
For example “.debug_info” for one of the DWARF custom sections or “name” for the names custom section.
Sourcefn data(&self, ids_to_indices: &IdsToIndices) -> Cow<'_, [u8]>
fn data(&self, ids_to_indices: &IdsToIndices) -> Cow<'_, [u8]>
Get the data payload for this custom section.
This should not include the section header with id=0, the custom
section’s name, or the count of how many bytes are in the
payload. walrus will handle these for you.
Provided Methods§
Sourcefn add_gc_roots(&self, _roots: &mut Roots)
fn add_gc_roots(&self, _roots: &mut Roots)
Add any core wasm roots to the provided roots argument.
This function will add any referenced core wasm items into the Roots
array provided.
The default provided method does nothing.
Sourcefn apply_code_transform(&mut self, transform: &CodeTransform)
fn apply_code_transform(&mut self, transform: &CodeTransform)
Apply the given code transformations to this custom section.
If the module was not configured with preserve_code_transform = true,
then this method is never called.
This method is called after we have emitted the non-custom Wasm sections, just before a custom section’s data is emitted into the Wasm binary. If this custom section references offsets in the Wasm code, this is a chance to update them so they are valid for the new, transformed Wasm code that is being emitted.
For example, DWARF debug info references Wasm instructions via offsets into the code section, and we can use these transforms to fix those offsets after having transformed various functions and instructions.
The default provided method does nothing.
Implementations§
Source§impl dyn CustomSection
impl dyn CustomSection
Sourcepub fn into_any(self: Box<Self>) -> Box<dyn Any + Send + 'static>
pub fn into_any(self: Box<Self>) -> Box<dyn Any + Send + 'static>
Convert this custom section to Box<Any> to do dynamic downcasting
Sourcepub fn as_any(&self) -> &(dyn Any + Send + Sync)
pub fn as_any(&self) -> &(dyn Any + Send + Sync)
Convert this custom section to &Any to do dynamic downcasting
Sourcepub fn as_any_mut(&mut self) -> &mut (dyn Any + Send + Sync)
pub fn as_any_mut(&mut self) -> &mut (dyn Any + Send + Sync)
Convert this custom section to &mut Any to do dynamic downcasting