[−][src]Struct walrus::ModuleCustomSections
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.
Methods
impl ModuleCustomSections
[src]
pub fn add<T>(&mut self, custom_section: T) -> TypedCustomSectionId<T> where
T: CustomSection,
[src]
T: CustomSection,
Add a new custom section to the module.
pub fn delete<I>(&mut self, id: I) -> Option<Box<I::CustomSection>> where
I: CustomSectionId,
[src]
I: CustomSectionId,
Remove a custom section from the module.
pub fn remove_raw(&mut self, name: &str) -> Option<RawCustomSection>
[src]
Take a raw, unparsed custom section out of this module.
pub fn get<T>(&self, id: T) -> Option<&T::CustomSection> where
T: CustomSectionId,
[src]
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
.
pub fn get_mut<T>(&mut self, id: T) -> Option<&mut T::CustomSection> where
T: CustomSectionId,
[src]
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
.
pub fn iter(
&self
) -> impl Iterator<Item = (UntypedCustomSectionId, &dyn CustomSection)>
[src]
&self
) -> impl Iterator<Item = (UntypedCustomSectionId, &dyn CustomSection)>
Iterate over shared references to custom sections and their ids.
pub fn iter_mut(
&mut self
) -> impl Iterator<Item = (UntypedCustomSectionId, &mut dyn CustomSection)>
[src]
&mut self
) -> impl Iterator<Item = (UntypedCustomSectionId, &mut dyn CustomSection)>
Iterate over exclusive references to custom sections and their ids.
pub fn delete_typed<T>(&mut self) -> Option<Box<T>> where
T: CustomSection,
[src]
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.
pub fn get_typed<T>(&self) -> Option<&T> where
T: CustomSection,
[src]
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.
pub fn get_typed_mut<T>(&mut self) -> Option<&mut T> where
T: CustomSection,
[src]
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.
Trait Implementations
impl Default for ModuleCustomSections
[src]
fn default() -> ModuleCustomSections
[src]
impl Debug for ModuleCustomSections
[src]
Auto Trait Implementations
impl Sync for ModuleCustomSections
impl Send for ModuleCustomSections
impl Unpin for ModuleCustomSections
impl !RefUnwindSafe for ModuleCustomSections
impl !UnwindSafe for ModuleCustomSections
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,