Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
41 changes: 40 additions & 1 deletion tsync-macro/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion tsync-macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -12,3 +12,5 @@ name = "tsync_macro"
path = "src/lib.rs"

[dependencies]
quote = "1.0.44"
syn = "2.0.114"
29 changes: 26 additions & 3 deletions tsync-macro/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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()
}