From: Dominik Csapak <d.csapak@proxmox.com>
To: yew-devel@lists.proxmox.com
Subject: [yew-devel] [PATCH yew-widget-toolkit 2/3] pwt-macros: builder: allow multiple generic types in callback variant
Date: Wed, 10 Dec 2025 11:48:49 +0100 [thread overview]
Message-ID: <20251210104856.1698157-3-d.csapak@proxmox.com> (raw)
In-Reply-To: <20251210104856.1698157-1-d.csapak@proxmox.com>
if there is a callback type with multiple generic variants, e.g.
Foo<A,B> we currently can't use it since we only expect one type
in the macro.
Extend the parser to add multiple types for the generic part.
So we can now write for example:
#[builder_cb(IntoEventCallback, into_event_callback, A, B)]
foo: Callback<A, B>,
This way it's compatible with the current way we write it.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
pwt-macros/src/builder.rs | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/pwt-macros/src/builder.rs b/pwt-macros/src/builder.rs
index 89f791e..ee28bbf 100644
--- a/pwt-macros/src/builder.rs
+++ b/pwt-macros/src/builder.rs
@@ -85,7 +85,7 @@ impl Parse for FieldOptions {
struct CallbackOptions {
into_trait: syn::Type,
into_fn: syn::Ident,
- inner_type: syn::Type,
+ inner_types: Vec<syn::Type>,
}
impl Parse for CallbackOptions {
@@ -105,16 +105,27 @@ impl Parse for CallbackOptions {
.parse()
.map_err(|err| Error::new(err.span(), format!("expected into function: {err}")))?;
+ let mut inner_types = Vec::new();
+
parse_comma(&content).map_err(|err| Error::new(err.span(), "missing inner type"))?;
let inner_type: syn::Type = content.parse().map_err(|err| {
Error::new(err.span(), format!("expected inner callback type: {err}"))
})?;
+ inner_types.push(inner_type);
+
+ while parse_comma(&content).is_ok() {
+ let inner_type: syn::Type = content.parse().map_err(|err| {
+ Error::new(err.span(), format!("expected inner callback type: {err}"))
+ })?;
+ inner_types.push(inner_type);
+ }
+
Ok(Self {
into_trait,
into_fn,
- inner_type,
+ inner_types,
})
}
}
@@ -229,9 +240,9 @@ fn derive_builder(builder: DeriveInput) -> Result<proc_macro2::TokenStream> {
let options = syn::parse2::<CallbackOptions>(tokens)?;
let into_fn = options.into_fn;
let into_trait = options.into_trait;
- let inner_type = options.inner_type;
+ let inner_types = options.inner_types;
(
- quote_spanned! { attr_span => impl #into_trait<#inner_type>},
+ quote_spanned! { attr_span => impl #into_trait<#(#inner_types),*>},
quote_spanned! { attr_span => #field_ident.#into_fn()},
)
}
--
2.47.3
_______________________________________________
yew-devel mailing list
yew-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel
next prev parent reply other threads:[~2025-12-10 10:48 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-10 10:48 [yew-devel] [RFC yew-comp/yew-widget-toolkit 0/4] make RenderFn's return type generic Dominik Csapak
2025-12-10 10:48 ` [yew-devel] [PATCH yew-widget-toolkit 1/3] pwt-macros: update tests to work for newer rustc Dominik Csapak
2025-12-10 10:48 ` Dominik Csapak [this message]
2025-12-10 10:48 ` [yew-devel] [PATCH yew-widget-toolkit 3/3] props: make RenderFn's return type generic Dominik Csapak
2025-12-10 10:48 ` [yew-devel] [PATCH yew-comp 1/1] rrd: replace TextRenderFn with new generic RenderFn Dominik Csapak
2025-12-11 9:35 ` [yew-devel] applied: [RFC yew-comp/yew-widget-toolkit 0/4] make RenderFn's return type generic Dietmar Maurer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251210104856.1698157-3-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=yew-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox