pub struct ComponentImportSection { /* private fields */ }
Expand description
An encoder for the import section of WebAssembly components.
§Example
use wasm_encoder::{Component, ComponentTypeSection, PrimitiveValType, ComponentImportSection, ComponentTypeRef};
let mut types = ComponentTypeSection::new();
// Define a function type of `[string, string] -> string`.
types
.function()
.params(
[
("a", PrimitiveValType::String),
("b", PrimitiveValType::String)
]
)
.result(Some(PrimitiveValType::String.into()));
// This imports a function named `f` with the type defined above
let mut imports = ComponentImportSection::new();
imports.import("f", ComponentTypeRef::Func(0));
let mut component = Component::new();
component.section(&types);
component.section(&imports);
let bytes = component.finish();
Implementations§
Source§impl ComponentImportSection
impl ComponentImportSection
Sourcepub fn new() -> Self
Available on crate feature component-model
only.
pub fn new() -> Self
component-model
only.Create a new component import section encoder.
Sourcepub fn len(&self) -> u32
Available on crate feature component-model
only.
pub fn len(&self) -> u32
component-model
only.The number of imports in the section.
Sourcepub fn is_empty(&self) -> bool
Available on crate feature component-model
only.
pub fn is_empty(&self) -> bool
component-model
only.Determines if the section is empty.
Sourcepub fn import(&mut self, name: &str, ty: ComponentTypeRef) -> &mut Self
Available on crate feature component-model
only.
pub fn import(&mut self, name: &str, ty: ComponentTypeRef) -> &mut Self
component-model
only.Define an import in the component import section.
Trait Implementations§
Source§impl Clone for ComponentImportSection
Available on crate feature component-model
only.
impl Clone for ComponentImportSection
Available on crate feature
component-model
only.Source§fn clone(&self) -> ComponentImportSection
fn clone(&self) -> ComponentImportSection
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl ComponentSection for ComponentImportSection
Available on crate feature component-model
only.
impl ComponentSection for ComponentImportSection
Available on crate feature
component-model
only.Source§impl Debug for ComponentImportSection
Available on crate feature component-model
only.
impl Debug for ComponentImportSection
Available on crate feature
component-model
only.Source§impl Default for ComponentImportSection
Available on crate feature component-model
only.
impl Default for ComponentImportSection
Available on crate feature
component-model
only.Source§fn default() -> ComponentImportSection
fn default() -> ComponentImportSection
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for ComponentImportSection
impl RefUnwindSafe for ComponentImportSection
impl Send for ComponentImportSection
impl Sync for ComponentImportSection
impl Unpin for ComponentImportSection
impl UnwindSafe for ComponentImportSection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more