diff --git a/examples/guide-supported-types-examples/exported_types.js b/examples/guide-supported-types-examples/exported_types.js index 7c60aea8..8119fece 100644 --- a/examples/guide-supported-types-examples/exported_types.js +++ b/examples/guide-supported-types-examples/exported_types.js @@ -1,14 +1,22 @@ import { - ExportedRustType, - exported_type_by_value, - exported_type_by_shared_ref, - exported_type_by_exclusive_ref, - return_exported_type, + ExportedNamedStruct, + named_struct_by_value, + named_struct_by_shared_ref, + named_struct_by_exclusive_ref, + return_named_struct, + + ExportedTupleStruct, + return_tuple_struct } from './guide_supported_types_examples'; -let rustThing = return_exported_type(); -console.log(rustThing instanceof ExportedRustType); // true +let namedStruct = return_named_struct(42); +console.log(namedStruct instanceof ExportedNamedStruct); // true +console.log(namedStruct.inner); // 42 -exported_type_by_value(rustThing); -exported_type_by_shared_ref(rustThing); -exported_type_by_exclusive_ref(rustThing); +named_struct_by_value(namedStruct); +named_struct_by_shared_ref(namedStruct); +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 diff --git a/examples/guide-supported-types-examples/src/exported_types.rs b/examples/guide-supported-types-examples/src/exported_types.rs index 963cb520..fb1ef1fc 100644 --- a/examples/guide-supported-types-examples/src/exported_types.rs +++ b/examples/guide-supported-types-examples/src/exported_types.rs @@ -1,20 +1,28 @@ use wasm_bindgen::prelude::*; #[wasm_bindgen] -pub struct ExportedRustType { - inner: u32, +pub struct ExportedNamedStruct { + pub inner: u32, } #[wasm_bindgen] -pub fn exported_type_by_value(x: ExportedRustType) {} +pub fn named_struct_by_value(x: ExportedNamedStruct) {} #[wasm_bindgen] -pub fn exported_type_by_shared_ref(x: &ExportedRustType) {} +pub fn named_struct_by_shared_ref(x: &ExportedNamedStruct) {} #[wasm_bindgen] -pub fn exported_type_by_exclusive_ref(x: &mut ExportedRustType) {} +pub fn named_struct_by_exclusive_ref(x: &mut ExportedNamedStruct) {} #[wasm_bindgen] -pub fn return_exported_type() -> ExportedRustType { - unimplemented!() +pub fn return_named_struct(inner: u32) -> ExportedNamedStruct { + 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) }