Skip to content

Commit

Permalink
feat: hello-world derive macro for composer (#90)
Browse files Browse the repository at this point in the history
* chore: Add hello-world derive macro

* refactor: format Cargo.toml file of workspace

* style: formatting cargo toml

---------

Co-authored-by: Shanith K K <[email protected]>
  • Loading branch information
ajaykumargdr and shanithkk authored Feb 19, 2024
1 parent e316bd3 commit 246aaca
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ members = [
# "workflow/composer-v2",
"primitives",
# "workflow/workflow_apis",
"workflow/test_util"
"workflow/test_util",
"workflow/hello_world_macro",
]

[workspace.package]
authors = ["The HugoByte Team <[email protected]>"]
edition = "2021"
repository = "https://github.com/hugobyte/aurras.git"
version = "0.0.1"
version = "0.0.1"
15 changes: 15 additions & 0 deletions workflow/hello_world_macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "hello_world_macro"
version = "0.0.1"
edition = "2018"
authors = ["HugoByte <[email protected]>"]
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
22 changes: 22 additions & 0 deletions workflow/hello_world_macro/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit 246aaca

Please sign in to comment.