mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-05-05 18:42:16 +00:00
Include props usage in exported_types example
This commit is contained in:
parent
3a7d384dc8
commit
a0a3a1446d
@ -1,14 +1,22 @@
|
|||||||
import {
|
import {
|
||||||
ExportedRustType,
|
ExportedNamedStruct,
|
||||||
exported_type_by_value,
|
named_struct_by_value,
|
||||||
exported_type_by_shared_ref,
|
named_struct_by_shared_ref,
|
||||||
exported_type_by_exclusive_ref,
|
named_struct_by_exclusive_ref,
|
||||||
return_exported_type,
|
return_named_struct,
|
||||||
|
|
||||||
|
ExportedTupleStruct,
|
||||||
|
return_tuple_struct
|
||||||
} from './guide_supported_types_examples';
|
} from './guide_supported_types_examples';
|
||||||
|
|
||||||
let rustThing = return_exported_type();
|
let namedStruct = return_named_struct(42);
|
||||||
console.log(rustThing instanceof ExportedRustType); // true
|
console.log(namedStruct instanceof ExportedNamedStruct); // true
|
||||||
|
console.log(namedStruct.inner); // 42
|
||||||
|
|
||||||
exported_type_by_value(rustThing);
|
named_struct_by_value(namedStruct);
|
||||||
exported_type_by_shared_ref(rustThing);
|
named_struct_by_shared_ref(namedStruct);
|
||||||
exported_type_by_exclusive_ref(rustThing);
|
named_struct_by_exclusive_ref(namedStruct);
|
||||||
|
|
||||||
|
let tupleStruct = return_tuple_struct(10, 20);
|
||||||
|
console.log(tupleStruct instanceof ExportedTupleStruct); // true
|
||||||
|
console.log(tupleStruct[0], tupleStruct[1]); // 10, 20
|
||||||
|
@ -1,20 +1,28 @@
|
|||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub struct ExportedRustType {
|
pub struct ExportedNamedStruct {
|
||||||
inner: u32,
|
pub inner: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn exported_type_by_value(x: ExportedRustType) {}
|
pub fn named_struct_by_value(x: ExportedNamedStruct) {}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn exported_type_by_shared_ref(x: &ExportedRustType) {}
|
pub fn named_struct_by_shared_ref(x: &ExportedNamedStruct) {}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn exported_type_by_exclusive_ref(x: &mut ExportedRustType) {}
|
pub fn named_struct_by_exclusive_ref(x: &mut ExportedNamedStruct) {}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn return_exported_type() -> ExportedRustType {
|
pub fn return_named_struct(inner: u32) -> ExportedNamedStruct {
|
||||||
unimplemented!()
|
ExportedNamedStruct { inner }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub struct ExportedTupleStruct(pub u32, pub u32);
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn return_tuple_struct(x: u32, y: u32) -> ExportedTupleStruct {
|
||||||
|
ExportedTupleStruct(x, y)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user