Add JsonField derive

This commit is contained in:
bitfl0wer 2023-08-04 16:41:37 +02:00
parent a51d524f46
commit 2fe95ccc06
No known key found for this signature in database
GPG Key ID: 0ACD574FCF5226CF
1 changed files with 19 additions and 0 deletions

View File

@ -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()
}