// This short example provides the utility to inspect // swasm file data section. extern crate swasm; use std::env; fn main() { // Example executable takes one argument which must // refernce the existing file with a valid swasm module let args = env::args().collect::>(); if args.len() != 2 { println!("Usage: {} somefile.swasm", args[0]); return; } // Here we load module using dedicated for this purpose // `deserialize_file` function (which works only with modules) let module = swasm::deserialize_file(&args[1]).expect("Failed to load module"); // We query module for data section. Note that not every valid // swasm module must contain a data section. So in case the provided // module does not contain data section, we panic with an error let data_section = module.data_section().expect("no data section in module"); // Printing the total count of data segments println!("Data segments: {}", data_section.entries().len()); let mut index = 0; for entry in data_section.entries() { // Printing the details info of each data segment // see `elements::DataSegment` for more properties // you can query println!(" Entry #{}", index); // This shows the initialization member of data segment // (expression which must resolve in the linear memory location). println!(" init: {}", entry.offset().code()[0]); // This shows the total length of the data segment in bytes. println!(" size: {}", entry.value().len()); index += 1; } }