From 41f5e5b2a0c42b76b3fad8b64e92d9034f0ff5cf Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 2 Apr 2020 15:59:07 +0200 Subject: [PATCH] doc(interface-types) Describe `to_interface_value`. --- src/interpreter/wasm/serde.rs | 41 ++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/interpreter/wasm/serde.rs b/src/interpreter/wasm/serde.rs index ed5b984..06db49f 100644 --- a/src/interpreter/wasm/serde.rs +++ b/src/interpreter/wasm/serde.rs @@ -67,7 +67,46 @@ where } } -/// foo +/// Serialize a type `T` that implements the `Serialize` trait to an +/// `InterfaceValue`. +/// +/// This is not a requirement to use WIT, but Serde provides an even +/// nicer API to the user to send its complex types to WIT. +/// +/// # Example +/// +/// ```rust +/// use wasmer_interface_types::interpreter::wasm::values::{ +/// InterfaceValue, +/// to_interface_value, +/// }; +/// use serde::Serialize; +/// +/// #[derive(Serialize)] +/// struct S(i32, i64); +/// +/// #[derive(Serialize)] +/// struct T { +/// x: String, +/// s: S, +/// y: f32, +/// }; +/// +/// let input = T { +/// x: "abc".to_string(), +/// s: S(1, 2), +/// y: 3., +/// }; +/// +/// assert_eq!( +/// to_interface_value(&input).unwrap(), +/// InterfaceValue::Record(vec![ +/// InterfaceValue::String("abc".to_string()), +/// InterfaceValue::Record(vec![InterfaceValue::I32(1), InterfaceValue::I64(2)]), +/// InterfaceValue::F32(3.), +/// ]), +/// ); +/// ``` pub fn to_interface_value(value: &T) -> Result where T: Serialize,