From 66cc7d1d6f231d32a118973650b13d637544fe7c Mon Sep 17 00:00:00 2001 From: AskSkivdal Date: Tue, 10 Feb 2026 09:36:02 +0100 Subject: [PATCH] Update the tsync macro to resolve #76 --- Cargo.lock | 16 +++++++++------- Cargo.toml | 3 ++- tsync-macro/Cargo.lock | 41 ++++++++++++++++++++++++++++++++++++++++- tsync-macro/Cargo.toml | 4 +++- tsync-macro/src/lib.rs | 29 ++++++++++++++++++++++++++--- 5 files changed, 80 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cd7f8b4..52cb17d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -255,9 +255,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.41" +version = "1.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1" +checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4" dependencies = [ "proc-macro2", ] @@ -387,9 +387,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "2.0.108" +version = "2.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da58917d35242480a05c2897064da0a80589a2a0476c9a3f2fdc83b53502e917" +checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a" dependencies = [ "proc-macro2", "quote", @@ -483,9 +483,11 @@ dependencies = [ [[package]] name = "tsync-macro" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8acc9e35a3072d9ea375093f321b3738ea3ac4fdebc18d2789b01581e5c2e4ae" +version = "0.2.0" +dependencies = [ + "quote", + "syn", +] [[package]] name = "unicode-ident" diff --git a/Cargo.toml b/Cargo.toml index 839403f..cbe8390 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,8 @@ syn = { version = "2.0", features = ["full", "extra-traits"] } proc-macro2 = "1.0.103" quote = "1.0.41" walkdir = "2.5.0" -tsync-macro = "0.1.0" +# Path is uesd localy, the version is used when published to crates.io +tsync-macro = { path = "tsync-macro", version = "0.2.0"} convert_case = "0.8.0" state = "0.6.0" diff --git a/tsync-macro/Cargo.lock b/tsync-macro/Cargo.lock index 7d90a9a..06399b0 100644 --- a/tsync-macro/Cargo.lock +++ b/tsync-macro/Cargo.lock @@ -1,7 +1,46 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "syn" +version = "2.0.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] [[package]] name = "tsync-macro" version = "0.1.0" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "unicode-ident" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "537dd038a89878be9b64dd4bd1b260315c1bb94f4d784956b81e27a088d9a09e" diff --git a/tsync-macro/Cargo.toml b/tsync-macro/Cargo.toml index bd66cfd..d75a07d 100644 --- a/tsync-macro/Cargo.toml +++ b/tsync-macro/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tsync-macro" -version = "0.1.0" +version = "0.2.0" edition = "2021" description = "Macros for tsync (see https://github.com/Wulf/tsync)" license = "MIT OR Apache-2.0" @@ -12,3 +12,5 @@ name = "tsync_macro" path = "src/lib.rs" [dependencies] +quote = "1.0.44" +syn = "2.0.114" diff --git a/tsync-macro/src/lib.rs b/tsync-macro/src/lib.rs index de5182b..b4005e2 100644 --- a/tsync-macro/src/lib.rs +++ b/tsync-macro/src/lib.rs @@ -1,9 +1,32 @@ -extern crate proc_macro; - use proc_macro::TokenStream; +use quote::quote; +use syn::{parse_macro_input, DeriveInput}; // document this attribute #[proc_macro_attribute] pub fn tsync(_attr: TokenStream, item: TokenStream) -> TokenStream { - item + let mut input = parse_macro_input!(item as DeriveInput); + + // Remove tsync decorators from struct fields + if let syn::Data::Struct(ref mut data) = input.data { + if let syn::Fields::Named(ref mut fields) = data.fields { + for field in fields.named.iter_mut() { + // Remove all tsync attributes + field.attrs.retain(|attr| !attr.path().is_ident("tsync")); + } + } + } + + if let syn::Data::Enum(ref mut data) = input.data { + for variant in data.variants.iter_mut() { + // Remove all tsync attributes + variant.attrs.retain(|attr| !attr.path().is_ident("tsync")); + } + } + + // Return the struct without the field-level tsync attributes + quote! { + #input + } + .into() }