From d5d2a3fac95ebd4c5ce779575b0f3fe97e560da0 Mon Sep 17 00:00:00 2001 From: ajaykumargdr Date: Mon, 19 Feb 2024 11:33:47 +0530 Subject: [PATCH 1/3] chore: Add hello-world derive macro --- Cargo.toml | 4 ++-- workflow/hello_world_macro/Cargo.toml | 15 +++++++++++++++ workflow/hello_world_macro/src/lib.rs | 22 ++++++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 workflow/hello_world_macro/Cargo.toml create mode 100644 workflow/hello_world_macro/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 52bf15bc..a8057a78 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,10 +19,10 @@ members = [ "primitives", # "workflow/workflow_apis", "workflow/test_util" -] +, "workflow/hello_world_macro"] [workspace.package] authors = ["The HugoByte Team "] edition = "2021" repository = "https://github.com/hugobyte/aurras.git" -version = "0.0.1" \ No newline at end of file +version = "0.0.1" diff --git a/workflow/hello_world_macro/Cargo.toml b/workflow/hello_world_macro/Cargo.toml new file mode 100644 index 00000000..00530309 --- /dev/null +++ b/workflow/hello_world_macro/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "hello_world_macro" +version = "0.0.1" +edition = "2018" +authors = ["HugoByte "] +repository = "https://github.com/HugoByte/aurras/workflow/hello_world_macro" +license = "Apache-2.0" +description = "Derive macro for hello world action" + +[dependencies] +quote = "1.0.33" +syn = "2.0.29" + +[lib] +proc-macro = true \ No newline at end of file diff --git a/workflow/hello_world_macro/src/lib.rs b/workflow/hello_world_macro/src/lib.rs new file mode 100644 index 00000000..a3db184a --- /dev/null +++ b/workflow/hello_world_macro/src/lib.rs @@ -0,0 +1,22 @@ +extern crate proc_macro; + +use proc_macro::TokenStream; +use syn::DeriveInput; + +#[proc_macro_derive(HelloWorldDerive)] +pub fn hello_world_derive_macro(item: TokenStream) -> TokenStream { + + let ast: DeriveInput = syn::parse(item).unwrap(); + let ident = ast.ident; + + quote::quote! { + impl #ident{ + pub fn run(&mut self) -> Result<(), String>{ + self.output = serde_json::to_value(format!("Hello {}", self.input.name)) + .map_err(|e|e.to_string())?; + Ok(()) + } + } + } + .into() +} From 5626863eda558be23314db8cd515717afec74aac Mon Sep 17 00:00:00 2001 From: ajaykumargdr Date: Mon, 19 Feb 2024 18:12:04 +0530 Subject: [PATCH 2/3] refactor: format Cargo.toml file of workspace --- Cargo.toml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a8057a78..9db6a949 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,8 +18,9 @@ members = [ # "workflow/composer-v2", "primitives", # "workflow/workflow_apis", - "workflow/test_util" -, "workflow/hello_world_macro"] + "workflow/test_util", + "workflow/hello_world_macro" +] [workspace.package] authors = ["The HugoByte Team "] From d14ac8170581f7fab60d27a2e80f01058ef53a77 Mon Sep 17 00:00:00 2001 From: Shanith K K Date: Mon, 19 Feb 2024 20:47:39 +0400 Subject: [PATCH 3/3] style: formatting cargo toml --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 9db6a949..ba0ae1ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ members = [ "primitives", # "workflow/workflow_apis", "workflow/test_util", - "workflow/hello_world_macro" + "workflow/hello_world_macro", ] [workspace.package]