pub struct DataSegment { /* private fields */ }Expand description
Data segment definition.
Implementations§
Source§impl DataSegment
impl DataSegment
Sourcepub fn offset(&self) -> &InitExpr
pub fn offset(&self) -> &InitExpr
An i32 initializer expression that computes the offset at which to place the data.
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}Sourcepub fn offset_mut(&mut self) -> &mut InitExpr
pub fn offset_mut(&mut self) -> &mut InitExpr
An i32 initializer expression that computes the offset at which to place the data (mutable)
Sourcepub fn value(&self) -> &[u8] ⓘ
pub fn value(&self) -> &[u8] ⓘ
Initial value of the data segment.
Examples found in repository?
examples/data.rs (line 42)
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}More examples
examples/info.rs (line 38)
6fn main() {
7 let args = env::args().collect::<Vec<_>>();
8 if args.len() != 2 {
9 println!("Usage: {} somefile.wasm", args[0]);
10 return;
11 }
12
13 let module = sophon_wasm::deserialize_file(&args[1]).expect("Failed to load module");
14
15 println!("Module sections: {}", module.sections().len());
16
17 for section in module.sections() {
18 match *section {
19 Section::Import(ref import_section) => {
20 println!(" Imports: {}", import_section.entries().len());
21 import_section.entries().iter().map(|e| println!(" {}.{}", e.module(), e.field())).count();
22 },
23 Section::Export(ref exports_section) => {
24 println!(" Exports: {}", exports_section.entries().len());
25 exports_section.entries().iter().map(|e| println!(" {}", e.field())).count();
26 },
27 Section::Function(ref function_section) => {
28 println!(" Functions: {}", function_section.entries().len());
29 },
30 Section::Type(ref type_section) => {
31 println!(" Types: {}", type_section.types().len());
32 },
33 Section::Global(ref globals_section) => {
34 println!(" Globals: {}", globals_section.entries().len());
35 },
36 Section::Data(ref data_section) if data_section.entries().len() > 0 => {
37 let data = &data_section.entries()[0];
38 println!(" Data size: {}", data.value().len());
39 },
40 _ => {},
41 }
42 }
43}Trait Implementations§
Source§impl Clone for DataSegment
impl Clone for DataSegment
Source§fn clone(&self) -> DataSegment
fn clone(&self) -> DataSegment
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 Deserialize for DataSegment
impl Deserialize for DataSegment
Auto Trait Implementations§
impl Freeze for DataSegment
impl RefUnwindSafe for DataSegment
impl Send for DataSegment
impl Sync for DataSegment
impl Unpin for DataSegment
impl UnwindSafe for DataSegment
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