Clone in a terminal:
Commit 840a569
Johan Mattsson - 2026-06-28T12:35:42+00:00
840a569b2c65dddee88f03afda2363d8dd9ca450johan.mattsson.m@gmail.com

Make all components derive default

Changed files (1)

Diff

diff --git a/src/lib.rs b/src/lib.rsindex 3d2f38e..94519aa 100644--- a/src/lib.rs+++ b/src/lib.rs@@ -1,8 +1,22 @@ mod init;  use proc_macro as pm;+use proc_macro2::TokenStream as TokenStream2;+use quote::quote;+use syn::ItemStruct;  #[proc_macro_attribute] pub fn component(attr: pm::TokenStream, item: pm::TokenStream) -> pm::TokenStream {-    init::component_impl(attr, item)+    // Add `#[derive(Default)]` to the struct.+    let item_ts2 = TokenStream2::from(item.clone());+    let mut input = match syn::parse2::<ItemStruct>(item_ts2.clone()) {+        Ok(s) => s,+        Err(_) => return init::component_impl(attr, item),+    };++    input.attrs.push(syn::parse_quote!(#[derive(Default)]));++    // Add the functions needed for a complete web component using kaja-web+    let new_item_ts2 = quote!(#input);+    init::component_impl(attr, pm::TokenStream::from(new_item_ts2)) }

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112