Struct wasm_encoder::DataSection
source · [−]pub struct DataSection { /* private fields */ }
Expand description
An encoder for the data section.
Data sections are only supported for modules.
Example
use wasm_encoder::{
ConstExpr, DataSection, Instruction, MemorySection, MemoryType,
Module,
};
let mut memory = MemorySection::new();
memory.memory(MemoryType {
minimum: 1,
maximum: None,
memory64: false,
shared: false,
});
let mut data = DataSection::new();
let memory_index = 0;
let offset = ConstExpr::i32_const(42);
let segment_data = b"hello";
data.active(memory_index, &offset, segment_data.iter().copied());
let mut module = Module::new();
module
.section(&memory)
.section(&data);
let wasm_bytes = module.finish();
Implementations
sourceimpl DataSection
impl DataSection
sourcepub fn segment<D>(&mut self, segment: DataSegment<'_, D>) -> &mut Self where
D: IntoIterator<Item = u8>,
D::IntoIter: ExactSizeIterator,
pub fn segment<D>(&mut self, segment: DataSegment<'_, D>) -> &mut Self where
D: IntoIterator<Item = u8>,
D::IntoIter: ExactSizeIterator,
Define a data segment.
sourcepub fn active<D>(
&mut self,
memory_index: u32,
offset: &ConstExpr,
data: D
) -> &mut Self where
D: IntoIterator<Item = u8>,
D::IntoIter: ExactSizeIterator,
pub fn active<D>(
&mut self,
memory_index: u32,
offset: &ConstExpr,
data: D
) -> &mut Self where
D: IntoIterator<Item = u8>,
D::IntoIter: ExactSizeIterator,
Define an active data segment.
sourcepub fn passive<D>(&mut self, data: D) -> &mut Self where
D: IntoIterator<Item = u8>,
D::IntoIter: ExactSizeIterator,
pub fn passive<D>(&mut self, data: D) -> &mut Self where
D: IntoIterator<Item = u8>,
D::IntoIter: ExactSizeIterator,
Define a passive data segment.
Passive data segments are part of the bulk memory proposal.
Trait Implementations
sourceimpl Clone for DataSection
impl Clone for DataSection
sourcefn clone(&self) -> DataSection
fn clone(&self) -> DataSection
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for DataSection
impl Debug for DataSection
sourceimpl Default for DataSection
impl Default for DataSection
sourcefn default() -> DataSection
fn default() -> DataSection
Returns the “default value” for a type. Read more
sourceimpl Encode for DataSection
impl Encode for DataSection
Auto Trait Implementations
impl RefUnwindSafe for DataSection
impl Send for DataSection
impl Sync for DataSection
impl Unpin for DataSection
impl UnwindSafe for DataSection
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more