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
MyCustomSectiontype to represent your custom section. -
Implement the
walrus::CustomSectiontrait for yourMyCustomSectiontype. -
When working with a
walrus::Modulenamedmy_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
MyCustomSectiontype in whatever way is appropriate. -
Do whatever kinds of inspection and manipulation of your
MyCustomSectiontype you need to do. -
Use
my_module.customs.add(my_custom_section)to add the custom section back into the module, sowalruscan 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.