From 2fe95ccc06d22cd50d25ec4ca962e97620db315e Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Fri, 4 Aug 2023 16:41:37 +0200 Subject: [PATCH] Add JsonField derive --- chorus-macros/src/lib.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/chorus-macros/src/lib.rs b/chorus-macros/src/lib.rs index c8d5e87..3a9397d 100644 --- a/chorus-macros/src/lib.rs +++ b/chorus-macros/src/lib.rs @@ -16,3 +16,22 @@ pub fn updateable_macro_derive(input: TokenStream) -> TokenStream { } .into() } + +#[proc_macro_derive(JsonField)] +pub fn jsonfield_macro_derive(input: TokenStream) -> TokenStream { + let ast: syn::DeriveInput = syn::parse(input).unwrap(); + + let name = &ast.ident; + // No need for macro hygiene, we're only using this in chorus + quote! { + impl JsonField for #name { + fn get_json(&self) -> String { + self.json.clone() + } + fn set_json(&mut self, json: String) { + self.json = json; + } + } + } + .into() +}