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 your MyCustomSection type.

  • When working with a walrus::Module named my_module, use my_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, so walrus can emit the processed/updated version of the custom section.

Implementations§

source§

impl ModuleCustomSections

source

pub fn add<T>(&mut self, custom_section: T) -> TypedCustomSectionId<T>where T: CustomSection,

Add a new custom section to the module.

source

pub fn delete<I>(&mut self, id: I) -> Option<Box<I::CustomSection>>where I: CustomSectionId,

Remove a custom section from the module.

source

pub fn remove_raw(&mut self, name: &str) -> Option<RawCustomSection>

Take a raw, unparsed custom section out of this module.

source

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.

source

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.

source

pub fn iter( &self ) -> impl Iterator<Item = (UntypedCustomSectionId, &dyn CustomSection)>

Iterate over shared references to custom sections and their ids.

source

pub fn iter_mut( &mut self ) -> impl Iterator<Item = (UntypedCustomSectionId, &mut dyn CustomSection)>

Iterate over exclusive references to custom sections and their ids.

source

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.

source

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.

source

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.

Trait Implementations§

source§

impl Debug for ModuleCustomSections

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for ModuleCustomSections

source§

fn default() -> ModuleCustomSections

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.