aboutsummaryrefslogtreecommitdiffstats
path: root/zotapi-derive
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2023-03-27 22:14:15 +0200
committerHarald Eilertsen <haraldei@anduin.net>2023-03-27 22:14:15 +0200
commitfe9db878e8f7d8f4bff2a51bb49b66ff84013644 (patch)
tree60d040e1f61d5c00e86389578b15a536a212aa43 /zotapi-derive
parent93ee81f05e1cb90c79949d5c57b1d7e3c272dd02 (diff)
downloadrust-zotapi-fe9db878e8f7d8f4bff2a51bb49b66ff84013644.tar.gz
rust-zotapi-fe9db878e8f7d8f4bff2a51bb49b66ff84013644.tar.bz2
rust-zotapi-fe9db878e8f7d8f4bff2a51bb49b66ff84013644.zip
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 :)
Diffstat (limited to 'zotapi-derive')
-rw-r--r--zotapi-derive/Cargo.toml13
-rw-r--r--zotapi-derive/src/lib.rs20
2 files changed, 33 insertions, 0 deletions
diff --git a/zotapi-derive/Cargo.toml b/zotapi-derive/Cargo.toml
new file mode 100644
index 0000000..72ece81
--- /dev/null
+++ b/zotapi-derive/Cargo.toml
@@ -0,0 +1,13 @@
+[package]
+name = "zotapi-derive"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+proc-macro2 = "1.0"
+quote = "1.0"
+syn = { version = "1.0", features = ["full"] }
+[lib]
+proc-macro = true
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()
+}