diff --git a/implementations/plugin-rust/build/wrap.wasm b/implementations/plugin-rust/build/wrap.wasm index b11f732d..3bd1f623 100755 Binary files a/implementations/plugin-rust/build/wrap.wasm and b/implementations/plugin-rust/build/wrap.wasm differ diff --git a/implementations/plugin-rust/src/__tests__/cases/000-sanity/output/module.rs b/implementations/plugin-rust/src/__tests__/cases/000-sanity/output/module.rs index db0deb79..59830fdf 100644 --- a/implementations/plugin-rust/src/__tests__/cases/000-sanity/output/module.rs +++ b/implementations/plugin-rust/src/__tests__/cases/000-sanity/output/module.rs @@ -4,6 +4,15 @@ use std::sync::Arc; use polywrap_core::invoke::Invoker; use polywrap_plugin::{error::PluginError, module::PluginModule}; +use polywrap_msgpack_serde::{ + to_vec, + from_slice, + BigIntWrapper, + BigNumber, + JSONString, + bytes +}; +use std::collections::BTreeMap; use serde::{Serialize, Deserialize}; use super::types::*; @@ -19,15 +28,15 @@ pub struct ArgsModuleMethod { pub enum_array: Vec, #[serde(rename = "optEnumArray")] pub opt_enum_array: Option>>, - pub map: Map, + pub map: BTreeMap, #[serde(rename = "mapOfArr")] - pub map_of_arr: Map>, + pub map_of_arr: BTreeMap>, #[serde(rename = "mapOfMap")] - pub map_of_map: Map>, + pub map_of_map: BTreeMap>, #[serde(rename = "mapOfObj")] - pub map_of_obj: Map, + pub map_of_obj: BTreeMap, #[serde(rename = "mapOfArrOfObj")] - pub map_of_arr_of_obj: Map>, + pub map_of_arr_of_obj: BTreeMap>, } #[derive(Clone, Debug, Deserialize, Serialize)] diff --git a/implementations/plugin-rust/src/__tests__/cases/000-sanity/output/types.rs b/implementations/plugin-rust/src/__tests__/cases/000-sanity/output/types.rs index fe3c1855..74cd3da5 100644 --- a/implementations/plugin-rust/src/__tests__/cases/000-sanity/output/types.rs +++ b/implementations/plugin-rust/src/__tests__/cases/000-sanity/output/types.rs @@ -4,8 +4,16 @@ // NOTE: This is an auto-generated file. // All modifications will be overwritten. use polywrap_core::{invoke::Invoker, uri::Uri}; -use polywrap_msgpack::{decode, serialize}; -use polywrap_plugin::{error::PluginError, BigInt, BigNumber, Map, JSON}; +use polywrap_plugin::error::PluginError; +use polywrap_msgpack_serde::{ + to_vec, + from_slice, + BigIntWrapper, + BigNumber, + JSONString, + bytes +}; +use std::collections::BTreeMap; use serde::{Serialize, Deserialize}; use std::sync::Arc; @@ -17,7 +25,7 @@ pub struct Env { #[serde(rename = "optProp")] pub opt_prop: Option, #[serde(rename = "optMap")] - pub opt_map: Option>>, + pub opt_map: Option>>, } // Env END // @@ -38,18 +46,18 @@ pub struct CustomType { pub i8: i8, pub i16: i16, pub i32: i32, - pub bigint: BigInt, + pub bigint: BigIntWrapper, #[serde(rename = "optBigint")] - pub opt_bigint: Option, + pub opt_bigint: Option, pub bignumber: BigNumber, #[serde(rename = "optBignumber")] pub opt_bignumber: Option, - pub json: JSON::Value, + pub json: JSONString, #[serde(rename = "optJson")] - pub opt_json: Option, - #[serde(with = "serde_bytes")] + pub opt_json: Option, + #[serde(with = "bytes")] pub bytes: Vec, - #[serde(with = "serde_bytes")] + #[serde(with = "bytes")] #[serde(rename = "optBytes")] pub opt_bytes: Option>, pub boolean: bool, @@ -84,15 +92,15 @@ pub struct CustomType { pub enum_array: Vec, #[serde(rename = "optEnumArray")] pub opt_enum_array: Option>>, - pub map: Map, + pub map: BTreeMap, #[serde(rename = "mapOfArr")] - pub map_of_arr: Map>, + pub map_of_arr: BTreeMap>, #[serde(rename = "mapOfObj")] - pub map_of_obj: Map, + pub map_of_obj: BTreeMap, #[serde(rename = "mapOfArrOfObj")] - pub map_of_arr_of_obj: Map>, + pub map_of_arr_of_obj: BTreeMap>, #[serde(rename = "mapCustomValue")] - pub map_custom_value: Map>, + pub map_custom_value: BTreeMap>, } #[derive(Clone, Debug, Deserialize, Serialize)] pub struct AnotherType { @@ -228,7 +236,7 @@ impl<'a> TestImportModule<'a> { pub fn imported_method(&self, args: &TestImportModuleArgsImportedMethod) -> Result, PluginError> { let uri = self.uri; - let serialized_args = serialize(args.clone()).unwrap(); + let serialized_args = to_vec(args.clone()).unwrap(); let result = invoker.invoke_raw( uri, "importedMethod", @@ -243,12 +251,12 @@ impl<'a> TestImportModule<'a> { exception: e.to_string(), })?; - Ok(Some(decode(result.as_slice())?)) + Ok(Some(from_slice(result.as_slice())?)) } pub fn another_method(&self, args: &TestImportModuleArgsAnotherMethod) -> Result { let uri = self.uri; - let serialized_args = serialize(args.clone()).unwrap(); + let serialized_args = to_vec(args.clone()).unwrap(); let result = invoker.invoke_raw( uri, "anotherMethod", @@ -263,12 +271,12 @@ impl<'a> TestImportModule<'a> { exception: e.to_string(), })?; - Ok(decode(result.as_slice())?) + Ok(from_slice(result.as_slice())?) } pub fn returns_array_of_enums(&self, args: &TestImportModuleArgsReturnsArrayOfEnums) -> Result>, PluginError> { let uri = self.uri; - let serialized_args = serialize(args.clone()).unwrap(); + let serialized_args = to_vec(args.clone()).unwrap(); let result = invoker.invoke_raw( uri, "returnsArrayOfEnums", @@ -283,7 +291,7 @@ impl<'a> TestImportModule<'a> { exception: e.to_string(), })?; - Ok(decode(result.as_slice())?) + Ok(from_slice(result.as_slice())?) } } // Imported Modules END // diff --git a/implementations/plugin-rust/src/__tests__/cases/001-module-functions/output/module.rs b/implementations/plugin-rust/src/__tests__/cases/001-module-functions/output/module.rs index 5c556535..547fe0b2 100644 --- a/implementations/plugin-rust/src/__tests__/cases/001-module-functions/output/module.rs +++ b/implementations/plugin-rust/src/__tests__/cases/001-module-functions/output/module.rs @@ -4,6 +4,15 @@ use std::sync::Arc; use polywrap_core::invoke::Invoker; use polywrap_plugin::{error::PluginError, module::PluginModule}; +use polywrap_msgpack_serde::{ + to_vec, + from_slice, + BigIntWrapper, + BigNumber, + JSONString, + bytes +}; +use std::collections::BTreeMap; use serde::{Serialize, Deserialize}; use super::types::*; @@ -16,7 +25,7 @@ pub struct ArgsFunction1 { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct ArgsFunction2 { pub arg1: Option, - #[serde(with = "serde_bytes")] + #[serde(with = "bytes")] pub arg2: Option>, } diff --git a/implementations/plugin-rust/src/__tests__/cases/001-module-functions/output/types.rs b/implementations/plugin-rust/src/__tests__/cases/001-module-functions/output/types.rs index a52e57b5..76b5f16e 100644 --- a/implementations/plugin-rust/src/__tests__/cases/001-module-functions/output/types.rs +++ b/implementations/plugin-rust/src/__tests__/cases/001-module-functions/output/types.rs @@ -4,8 +4,16 @@ // NOTE: This is an auto-generated file. // All modifications will be overwritten. use polywrap_core::{invoke::Invoker, uri::Uri}; -use polywrap_msgpack::{decode, serialize}; -use polywrap_plugin::{error::PluginError, BigInt, BigNumber, Map, JSON}; +use polywrap_plugin::error::PluginError; +use polywrap_msgpack_serde::{ + to_vec, + from_slice, + BigIntWrapper, + BigNumber, + JSONString, + bytes +}; +use std::collections::BTreeMap; use serde::{Serialize, Deserialize}; // Env START // diff --git a/implementations/plugin-rust/src/__tests__/cases/002-object-types/output/module.rs b/implementations/plugin-rust/src/__tests__/cases/002-object-types/output/module.rs index 78a190e2..4e591a39 100644 --- a/implementations/plugin-rust/src/__tests__/cases/002-object-types/output/module.rs +++ b/implementations/plugin-rust/src/__tests__/cases/002-object-types/output/module.rs @@ -4,6 +4,15 @@ use std::sync::Arc; use polywrap_core::invoke::Invoker; use polywrap_plugin::{error::PluginError, module::PluginModule}; +use polywrap_msgpack_serde::{ + to_vec, + from_slice, + BigIntWrapper, + BigNumber, + JSONString, + bytes +}; +use std::collections::BTreeMap; use serde::{Serialize, Deserialize}; use super::types::*; diff --git a/implementations/plugin-rust/src/__tests__/cases/002-object-types/output/types.rs b/implementations/plugin-rust/src/__tests__/cases/002-object-types/output/types.rs index 8bdeb0df..05c9ee5f 100644 --- a/implementations/plugin-rust/src/__tests__/cases/002-object-types/output/types.rs +++ b/implementations/plugin-rust/src/__tests__/cases/002-object-types/output/types.rs @@ -4,8 +4,16 @@ // NOTE: This is an auto-generated file. // All modifications will be overwritten. use polywrap_core::{invoke::Invoker, uri::Uri}; -use polywrap_msgpack::{decode, serialize}; -use polywrap_plugin::{error::PluginError, BigInt, BigNumber, Map, JSON}; +use polywrap_plugin::error::PluginError; +use polywrap_msgpack_serde::{ + to_vec, + from_slice, + BigIntWrapper, + BigNumber, + JSONString, + bytes +}; +use std::collections::BTreeMap; use serde::{Serialize, Deserialize}; // Env START // @@ -29,18 +37,18 @@ pub struct CustomType { pub i8: i8, pub i16: i16, pub i32: i32, - pub bigint: BigInt, + pub bigint: BigIntWrapper, #[serde(rename = "optBigint")] - pub opt_bigint: Option, + pub opt_bigint: Option, pub bignumber: BigNumber, #[serde(rename = "optBignumber")] pub opt_bignumber: Option, - pub json: JSON::Value, + pub json: JSONString, #[serde(rename = "optJson")] - pub opt_json: Option, - #[serde(with = "serde_bytes")] + pub opt_json: Option, + #[serde(with = "bytes")] pub bytes: Vec, - #[serde(with = "serde_bytes")] + #[serde(with = "bytes")] #[serde(rename = "optBytes")] pub opt_bytes: Option>, pub boolean: bool, @@ -68,15 +76,15 @@ pub struct CustomType { pub object_array: Vec, #[serde(rename = "optObjectArray")] pub opt_object_array: Option>>, - pub map: Map, + pub map: BTreeMap, #[serde(rename = "mapOfArr")] - pub map_of_arr: Map>, + pub map_of_arr: BTreeMap>, #[serde(rename = "mapOfObj")] - pub map_of_obj: Map, + pub map_of_obj: BTreeMap, #[serde(rename = "mapOfArrOfObj")] - pub map_of_arr_of_obj: Map>, + pub map_of_arr_of_obj: BTreeMap>, #[serde(rename = "mapCustomValue")] - pub map_custom_value: Map>, + pub map_custom_value: BTreeMap>, } #[derive(Clone, Debug, Deserialize, Serialize)] pub struct AnotherType { diff --git a/implementations/plugin-rust/src/helpers/serde_annotate_if_bytes.rs b/implementations/plugin-rust/src/helpers/serde_annotate_if_bytes.rs index 2305b54b..58a56d45 100644 --- a/implementations/plugin-rust/src/helpers/serde_annotate_if_bytes.rs +++ b/implementations/plugin-rust/src/helpers/serde_annotate_if_bytes.rs @@ -8,7 +8,7 @@ handlebars_helper!(serde_annotate_if_bytes: |val: Value| { pub fn _serde_annotate_if_bytes(val: &str) -> String { if val == "Bytes" { - return "#[serde(with = \"serde_bytes\")]\n ".to_string(); + return "#[serde(with = \"bytes\")]\n ".to_string(); } "".to_string() } diff --git a/implementations/plugin-rust/src/helpers/to_rust.rs b/implementations/plugin-rust/src/helpers/to_rust.rs index e19b1566..6eccbb05 100644 --- a/implementations/plugin-rust/src/helpers/to_rust.rs +++ b/implementations/plugin-rust/src/helpers/to_rust.rs @@ -38,9 +38,9 @@ pub fn _to_rust(value: &str) -> String { "String" => "String".to_string(), "Boolean" => "bool".to_string(), "Bytes" => "Vec".to_string(), - "BigInt" => "BigInt".to_string(), + "BigInt" => "BigIntWrapper".to_string(), "BigNumber" => "BigNumber".to_string(), - "JSON" => "JSON::Value".to_string(), + "JSON" => "JSONString".to_string(), _ => { if res.starts_with("Enum_") { res = res.replacen("Enum_", "", 1); @@ -64,7 +64,7 @@ pub fn _to_rust_map(value: &str, optional: bool) -> Result { let (key_type, val_type) = map_types(value)?; let rs_key_type = _to_rust(&key_type); let rs_val_type = _to_rust(&val_type); - let rs_map = format!("Map<{}, {}>", &rs_key_type, &rs_val_type); + let rs_map = format!("BTreeMap<{}, {}>", &rs_key_type, &rs_val_type); Ok(_apply_optional(&rs_map, optional)) } diff --git a/implementations/plugin-rust/src/templates/module_rs.rs b/implementations/plugin-rust/src/templates/module_rs.rs index 70d8dd43..29106f06 100644 --- a/implementations/plugin-rust/src/templates/module_rs.rs +++ b/implementations/plugin-rust/src/templates/module_rs.rs @@ -6,6 +6,15 @@ lazy_static! { use std::sync::Arc; use polywrap_core::invoke::Invoker; use polywrap_plugin::{error::PluginError, module::PluginModule}; +use polywrap_msgpack_serde::{ + to_vec, + from_slice, + BigIntWrapper, + BigNumber, + JSONString, + bytes +}; +use std::collections::BTreeMap; use serde::{Serialize, Deserialize}; use super::types::*; diff --git a/implementations/plugin-rust/src/templates/types_rs.rs b/implementations/plugin-rust/src/templates/types_rs.rs index ede0b088..97110648 100644 --- a/implementations/plugin-rust/src/templates/types_rs.rs +++ b/implementations/plugin-rust/src/templates/types_rs.rs @@ -6,8 +6,16 @@ lazy_static! { // NOTE: This is an auto-generated file. // All modifications will be overwritten. use polywrap_core::{invoke::Invoker, uri::Uri}; -use polywrap_msgpack::{decode, serialize}; -use polywrap_plugin::{error::PluginError, BigInt, BigNumber, Map, JSON}; +use polywrap_plugin::error::PluginError; +use polywrap_msgpack_serde::{ + to_vec, + from_slice, + BigIntWrapper, + BigNumber, + JSONString, + bytes +}; +use std::collections::BTreeMap; use serde::{Serialize, Deserialize}; {{#each importedModuleTypes}} use std::sync::Arc; @@ -116,7 +124,7 @@ impl<'a> {{detect_keyword (to_upper type)}}<'a> { {{#each methods}} pub fn {{to_lower name}}(&self, args: &{{to_upper ../type}}Args{{to_upper name}}) -> Result<{{#with return}}{{to_rust (to_graphql_type this)}}{{/with}}, PluginError> { let uri = self.uri; - let serialized_args = serialize(args.clone()).unwrap(); + let serialized_args = to_vec(args.clone()).unwrap(); let result = invoker.invoke_raw( uri, "{{name}}", @@ -131,7 +139,7 @@ impl<'a> {{detect_keyword (to_upper type)}}<'a> { exception: e.to_string(), })?; - Ok({{#with return}}{{#if required}}{{else}}Some({{/if}}{{/with}}decode(result.as_slice())?{{#with return}}{{#if required}}{{else}}){{/if}}{{/with}}) + Ok({{#with return}}{{#if required}}{{else}}Some({{/if}}{{/with}}from_slice(result.as_slice())?{{#with return}}{{#if required}}{{else}}){{/if}}{{/with}}) } {{#if (is_not_last @index ../methods)}} @@ -152,7 +160,7 @@ impl {{detect_keyword (to_upper type)}} { {{#each methods}} let uri = {{to_upper ../type}}::URI; pub fn {{detect_keyword (to_lower name)}}(args: &{{to_upper ../type}}Args{{to_upper name}}, invoker: Arc) -> Result<{{#with return}}{{to_rust (to_graphql_type this)}}{{/with}}, PluginError> { - let serialized_args = serialize(args.clone()).unwrap(); + let serialized_args = to_vec(args.clone()).unwrap(); let opt_args = Some(serialized_args.as_slice()); let uri = Uri::try_from(uri).unwrap(); let result = invoker.invoke_raw( @@ -169,7 +177,7 @@ impl {{detect_keyword (to_upper type)}} { exception: e.to_string(), })?; - Ok({{#with return}}{{#if required}}{{else}}Some({{/if}}{{/with}}decode(result.as_slice())?{{#with return}}{{#if required}}{{else}}){{/if}}{{/with}}) + Ok({{#with return}}{{#if required}}{{else}}Some({{/if}}{{/with}}from_slice(result.as_slice())?{{#with return}}{{#if required}}{{else}}){{/if}}{{/with}}) } {{#if (is_not_last @index ../methods)}}