From ce5c3794c2f8b2c2c9a2f8de111166619f4552b2 Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Mon, 12 Dec 2022 21:47:08 -0500 Subject: [PATCH 1/2] fix: use String class for imported interface modules --- .../imported/module-type/mod-rs.mustache | 12 +++++------ .../imported/test_import_module/mod.rs | 20 +++++++++---------- .../test-use-getImpl/src/lib.rs | 3 +-- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/packages/schema/bind/src/bindings/rust/wasm/templates/imported/module-type/mod-rs.mustache b/packages/schema/bind/src/bindings/rust/wasm/templates/imported/module-type/mod-rs.mustache index c8cc0c8389..15c0a86ee0 100644 --- a/packages/schema/bind/src/bindings/rust/wasm/templates/imported/module-type/mod-rs.mustache +++ b/packages/schema/bind/src/bindings/rust/wasm/templates/imported/module-type/mod-rs.mustache @@ -55,24 +55,24 @@ impl {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}} { {{/isInterface}} {{#isInterface}} #[derive(Clone, Debug, Deserialize, Serialize)] -pub struct {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}}<'a> { - {{#isInterface}}uri: &'a str{{/isInterface}} +pub struct {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}} { + {{#isInterface}}uri: String;{{/isInterface}} } -impl<'a> {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}}<'a> { +impl {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}} { pub const INTERFACE_URI: &'static str = "{{uri}}"; - pub fn new(uri: &'a str) -> {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}}<'a> { + pub fn new(uri: String) -> {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}} { {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}} { uri: uri } } {{#methods}} pub fn {{#toLower}}{{name}}{{/toLower}}(&self, args: &Args{{#toUpper}}{{name}}{{/toUpper}}) -> Result<{{#return}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/return}}, String> { - let uri = self.uri; + let ref uri = self.uri; let args = serialize_{{#toLower}}{{name}}{{/toLower}}_args(args).map_err(|e| e.to_string())?; let result = subinvoke::wrap_subinvoke( uri, - "{{name}}", + "{{name}}".as_str(), args, )?; deserialize_{{#toLower}}{{name}}{{/toLower}}_result(result.as_slice()).map_err(|e| e.to_string()) diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-rs/imported/test_import_module/mod.rs b/packages/test-cases/cases/bind/sanity/output/wasm-rs/imported/test_import_module/mod.rs index 8d14dd988c..430e1dbcfb 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-rs/imported/test_import_module/mod.rs +++ b/packages/test-cases/cases/bind/sanity/output/wasm-rs/imported/test_import_module/mod.rs @@ -26,22 +26,22 @@ use crate::TestImportEnum; use crate::TestImportEnumReturn; #[derive(Clone, Debug, Deserialize, Serialize)] -pub struct TestImportModule<'a> { - uri: &'a str +pub struct TestImportModule { + uri: String; } -impl<'a> TestImportModule<'a> { +impl TestImportModule { pub const INTERFACE_URI: &'static str = "testimport.uri.eth"; - pub fn new(uri: &'a str) -> TestImportModule<'a> { + pub fn new(uri: String) -> TestImportModule { TestImportModule { uri: uri } } pub fn imported_method(&self, args: &ArgsImportedMethod) -> Result, String> { - let uri = self.uri; + let ref uri = self.uri; let args = serialize_imported_method_args(args).map_err(|e| e.to_string())?; let result = subinvoke::wrap_subinvoke( - uri, + uri.as_str(), "importedMethod", args, )?; @@ -49,10 +49,10 @@ impl<'a> TestImportModule<'a> { } pub fn another_method(&self, args: &ArgsAnotherMethod) -> Result { - let uri = self.uri; + let ref uri = self.uri; let args = serialize_another_method_args(args).map_err(|e| e.to_string())?; let result = subinvoke::wrap_subinvoke( - uri, + uri.as_str(), "anotherMethod", args, )?; @@ -60,10 +60,10 @@ impl<'a> TestImportModule<'a> { } pub fn returns_array_of_enums(&self, args: &ArgsReturnsArrayOfEnums) -> Result>, String> { - let uri = self.uri; + let ref uri = self.uri; let args = serialize_returns_array_of_enums_args(args).map_err(|e| e.to_string())?; let result = subinvoke::wrap_subinvoke( - uri, + uri.as_str(), "returnsArrayOfEnums", args, )?; diff --git a/packages/test-cases/cases/wrappers/wasm-rs/implementations/test-use-getImpl/src/lib.rs b/packages/test-cases/cases/wrappers/wasm-rs/implementations/test-use-getImpl/src/lib.rs index beadad39df..3fda9b668e 100644 --- a/packages/test-cases/cases/wrappers/wasm-rs/implementations/test-use-getImpl/src/lib.rs +++ b/packages/test-cases/cases/wrappers/wasm-rs/implementations/test-use-getImpl/src/lib.rs @@ -13,8 +13,7 @@ pub fn module_method(args: ArgsModuleMethod) -> ImplementationType { pub fn abstract_module_method(args: ArgsAbstractModuleMethod) -> String { let impls = Interface::get_implementations(); - let uri: String = impls[0].to_owned(); - let module = InterfaceModule::new(&uri); + let module = InterfaceModule::new(impls[0].clone()); let method_args = interface_module::serialization::ArgsAbstractModuleMethod { arg: interface_argument::InterfaceArgument { str: args.arg.str From 25f7b01f2ee5e31088fe2d9dff0d60637245b586 Mon Sep 17 00:00:00 2001 From: krisbitney Date: Tue, 13 Dec 2022 09:17:24 +0530 Subject: [PATCH 2/2] fix: moved as_string() from string literal to class property reference in rs imported mod binding --- .../wasm/templates/imported/module-type/mod-rs.mustache | 8 ++++---- .../output/wasm-rs/imported/test_import_module/mod.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/schema/bind/src/bindings/rust/wasm/templates/imported/module-type/mod-rs.mustache b/packages/schema/bind/src/bindings/rust/wasm/templates/imported/module-type/mod-rs.mustache index 15c0a86ee0..68a3c9bb93 100644 --- a/packages/schema/bind/src/bindings/rust/wasm/templates/imported/module-type/mod-rs.mustache +++ b/packages/schema/bind/src/bindings/rust/wasm/templates/imported/module-type/mod-rs.mustache @@ -56,14 +56,14 @@ impl {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}} { {{#isInterface}} #[derive(Clone, Debug, Deserialize, Serialize)] pub struct {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}} { - {{#isInterface}}uri: String;{{/isInterface}} + {{#isInterface}}uri: String{{/isInterface}} } impl {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}} { pub const INTERFACE_URI: &'static str = "{{uri}}"; pub fn new(uri: String) -> {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}} { - {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}} { uri: uri } + {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}} { uri } } {{#methods}} @@ -71,8 +71,8 @@ impl {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}} { let ref uri = self.uri; let args = serialize_{{#toLower}}{{name}}{{/toLower}}_args(args).map_err(|e| e.to_string())?; let result = subinvoke::wrap_subinvoke( - uri, - "{{name}}".as_str(), + uri.as_str(), + "{{name}}", args, )?; deserialize_{{#toLower}}{{name}}{{/toLower}}_result(result.as_slice()).map_err(|e| e.to_string()) diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-rs/imported/test_import_module/mod.rs b/packages/test-cases/cases/bind/sanity/output/wasm-rs/imported/test_import_module/mod.rs index 430e1dbcfb..d265f90a57 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-rs/imported/test_import_module/mod.rs +++ b/packages/test-cases/cases/bind/sanity/output/wasm-rs/imported/test_import_module/mod.rs @@ -27,14 +27,14 @@ use crate::TestImportEnumReturn; #[derive(Clone, Debug, Deserialize, Serialize)] pub struct TestImportModule { - uri: String; + uri: String } impl TestImportModule { pub const INTERFACE_URI: &'static str = "testimport.uri.eth"; pub fn new(uri: String) -> TestImportModule { - TestImportModule { uri: uri } + TestImportModule { uri } } pub fn imported_method(&self, args: &ArgsImportedMethod) -> Result, String> {