InitExpr

Struct InitExpr 

Source
pub struct InitExpr(/* private fields */);
Expand description

Initialization expression.

Implementations§

Source§

impl InitExpr

Source

pub fn new(code: Vec<Opcode>) -> Self

New initialization expression from list of opcodes. code must end with the Opcode::End opcode!

Source

pub fn empty() -> Self

Empty expression with only Opcode::End opcode

Source

pub fn code(&self) -> &[Opcode]

List of opcodes used in the expression.

Examples found in repository?
examples/data.rs (line 39)
8fn main() {
9
10    // Example executable takes one argument which must
11    // refernce the existing file with a valid wasm module
12    let args = env::args().collect::<Vec<_>>();
13    if args.len() != 2 {
14        println!("Usage: {} somefile.wasm", args[0]);
15        return;
16    }
17
18    // Here we load module using dedicated for this purpose
19    // `deserialize_file` function (which works only with modules)
20    let module = sophon_wasm::deserialize_file(&args[1]).expect("Failed to load module");
21
22    // We query module for data section. Note that not every valid
23    // wasm module must contain a data section. So in case the provided
24    // module does not contain data section, we panic with an error
25    let data_section = module.data_section().expect("no data section in module");
26
27    // Printing the total count of data segments
28    println!("Data segments: {}", data_section.entries().len());
29
30    let mut index = 0;
31    for entry in data_section.entries() {
32        // Printing the details info of each data segment
33        // see `elements::DataSegment` for more properties
34        // you can query
35        println!("  Entry #{}", index);
36
37        // This shows the initialization member of data segment
38        // (expression which must resolve in the linear memory location).
39        println!("    init: {}", entry.offset().code()[0]);
40
41        // This shows the total length of the data segment in bytes.
42        println!("    size: {}", entry.value().len());
43
44        index += 1;
45    }
46}
Source

pub fn code_mut(&mut self) -> &mut Vec<Opcode>

List of opcodes used in the expression.

Trait Implementations§

Source§

impl Clone for InitExpr

Source§

fn clone(&self) -> InitExpr

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for InitExpr

Source§

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

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

impl Deserialize for InitExpr

Source§

type Error = Error

Serialization error produced by deserialization routine.
Source§

fn deserialize<R: Read>(reader: &mut R) -> Result<Self, Self::Error>

Deserialize type from serial i/o
Source§

impl Serialize for InitExpr

Source§

type Error = Error

Serialization error produced by serialization routine.
Source§

fn serialize<W: Write>(self, writer: &mut W) -> Result<(), Self::Error>

Serialize type to serial i/o

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

impl<T> Erased for T