[][src]Struct walrus::ModuleCustomSections

pub struct ModuleCustomSections { /* fields omitted */ }

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.

Methods

impl ModuleCustomSections[src]

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

Add a new custom section to the module.

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

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]

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]

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]

Iterate over shared references to custom sections and their ids.

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

Iterate over exclusive references to custom sections and their ids.

pub fn delete_typed<T>(&mut self) -> Option<Box<T>> where
    T: CustomSection
[src]

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]

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]

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]

impl Debug for ModuleCustomSections[src]

Auto Trait Implementations

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]