From fe9db878e8f7d8f4bff2a51bb49b66ff84013644 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Mon, 27 Mar 2023 22:14:15 +0200 Subject: Add ZotAPI trait and derive macro. The idea is to try to generate more of the boilerplate code, but for now we only do the `z()` method definition. There are also some we're not quite able to replace yet (like XChanRequest) since it also has life times. It's a start anyways :) --- zotapi-derive/src/lib.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 zotapi-derive/src/lib.rs (limited to 'zotapi-derive/src') diff --git a/zotapi-derive/src/lib.rs b/zotapi-derive/src/lib.rs new file mode 100644 index 0000000..ff44c9c --- /dev/null +++ b/zotapi-derive/src/lib.rs @@ -0,0 +1,20 @@ +use proc_macro::{self, TokenStream}; +use quote::*; +use syn::DeriveInput; + +#[proc_macro_derive(ZotAPI)] +pub fn zotapi_derive(input: TokenStream) -> TokenStream { + let ast = syn::parse(input).unwrap(); + impl_zotapi_derive(&ast) +} + +fn impl_zotapi_derive(ast: &DeriveInput) -> TokenStream { + let name = &ast.ident; // The identifier of the struct we're called for + let out_name = format_ident!("{}Request", name); + + let gen = quote! { + impl ZotAPI<#out_name> for #name { + } + }; + gen.into() +} -- cgit v1.2.3