From 9ebaf8cd5d89f244548b5e1089e311ea4532b44a Mon Sep 17 00:00:00 2001 From: Janis Date: Sun, 25 Jun 2023 13:43:52 +0200 Subject: [PATCH] generate method trait --- sdk-builder/src/main.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/sdk-builder/src/main.rs b/sdk-builder/src/main.rs index 0ea00ab..5dd63a9 100644 --- a/sdk-builder/src/main.rs +++ b/sdk-builder/src/main.rs @@ -644,7 +644,7 @@ pub mod rust { match find_object(::obfstr::obfstr!("#name")) { object @ Some(_) => {object}, None => { - ::log::error!("{}", obfstr::obfstr!("static object {#name} not found!")); + ::log::error!("{}", obfstr::obfstr!("static object #name not found!")); } } }) @@ -665,6 +665,22 @@ pub mod rust { StructKind::Struct => self.generate_struct(class, name, ctor)?, }; + let (method_params, methods) = self.generate_struct_methods(class, &name)?; + + let method_trait = format_ident!("{name}Methods"); + + let methods = quote! { + #(#method_params)* + + pub trait #method_trait { + #(#methods)* + } + + impl #method_trait for #name {} + }; + + // TODO: impl super-type fields and methods. + quote! { #[repr(transparent)] #[derive(Debug)] @@ -675,6 +691,8 @@ pub mod rust { #impls + #methods + #field_trait }; todo!()