Struct walrus::ModuleCustomSections
source · pub struct ModuleCustomSections { /* private fields */ }
Expand description
A collection of custom sections inside a Wasm module.
To add parse and emit your own custom section:
-
Define a
MyCustomSection
type to represent your custom section. -
Implement the
walrus::CustomSection
trait for yourMyCustomSection
type. -
When working with a
walrus::Module
namedmy_module
, usemy_module.customs.take_raw("my_custom_section_name")
to take ownership of the raw custom section if it is present in the Wasm module. -
Parse that into your own
MyCustomSection
type in whatever way is appropriate. -
Do whatever kinds of inspection and manipulation of your
MyCustomSection
type you need to do. -
Use
my_module.customs.add(my_custom_section)
to add the custom section back into the module, sowalrus
can emit the processed/updated version of the custom section.
Implementations§
source§impl ModuleCustomSections
impl ModuleCustomSections
sourcepub fn add<T>(&mut self, custom_section: T) -> TypedCustomSectionId<T>where
T: CustomSection,
pub fn add<T>(&mut self, custom_section: T) -> TypedCustomSectionId<T>where T: CustomSection,
Add a new custom section to the module.
sourcepub fn delete<I>(&mut self, id: I) -> Option<Box<I::CustomSection>>where
I: CustomSectionId,
pub fn delete<I>(&mut self, id: I) -> Option<Box<I::CustomSection>>where I: CustomSectionId,
Remove a custom section from the module.
sourcepub fn remove_raw(&mut self, name: &str) -> Option<RawCustomSection>
pub fn remove_raw(&mut self, name: &str) -> Option<RawCustomSection>
Take a raw, unparsed custom section out of this module.
sourcepub fn get<T>(&self, id: T) -> Option<&T::CustomSection>where
T: CustomSectionId,
pub fn get<T>(&self, id: T) -> Option<&T::CustomSection>where T: CustomSectionId,
Try and get a shared reference to a custom section that is in this
ModuleCustomSections
.
Returns None
if the section associated with the given id
has been
taken or deleted, or if it is present but not an instance of
T::CustomSection
.
sourcepub fn get_mut<T>(&mut self, id: T) -> Option<&mut T::CustomSection>where
T: CustomSectionId,
pub fn get_mut<T>(&mut self, id: T) -> Option<&mut T::CustomSection>where T: CustomSectionId,
Try and get an exclusive reference to a custom section that is in this
ModuleCustomSections
.
Returns None
if the section associated with the given id
has been
taken or deleted, or if it is present but not an instance of
T::CustomSection
.
sourcepub fn iter(
&self
) -> impl Iterator<Item = (UntypedCustomSectionId, &dyn CustomSection)>
pub fn iter( &self ) -> impl Iterator<Item = (UntypedCustomSectionId, &dyn CustomSection)>
Iterate over shared references to custom sections and their ids.
sourcepub fn iter_mut(
&mut self
) -> impl Iterator<Item = (UntypedCustomSectionId, &mut dyn CustomSection)>
pub fn iter_mut( &mut self ) -> impl Iterator<Item = (UntypedCustomSectionId, &mut dyn CustomSection)>
Iterate over exclusive references to custom sections and their ids.
sourcepub fn delete_typed<T>(&mut self) -> Option<Box<T>>where
T: CustomSection,
pub fn delete_typed<T>(&mut self) -> Option<Box<T>>where T: CustomSection,
Remove a custom section (by type) from the module.
If there are multiple custom sections of the type T
only the first one
is removed.
sourcepub fn get_typed<T>(&self) -> Option<&T>where
T: CustomSection,
pub fn get_typed<T>(&self) -> Option<&T>where T: CustomSection,
Get a shared reference to a custom section, by type.
If there are multiple custom sections of the type T
this returns a
reference to the first one.
sourcepub fn get_typed_mut<T>(&mut self) -> Option<&mut T>where
T: CustomSection,
pub fn get_typed_mut<T>(&mut self) -> Option<&mut T>where T: CustomSection,
Get a mutable reference to a custom section, by type.
If there are multiple custom sections of the type T
this returns a
reference to the first one.