From e261c47a549f4dc15f1b47efd1916acc2dbcee9e Mon Sep 17 00:00:00 2001 From: Harrison McCullough Date: Sun, 12 Apr 2026 07:43:23 -0700 Subject: [PATCH 1/2] Support tuple structs in wrap_impl! Change the fragment specifier used in `wrap_impl!` from `ident` to `tt`. Using `ident` was sufficient for "standard" structs with named fields. However, tuple structs are accessed via index numbers, which are not matched by `ident`. Although using `literal` for tuple indices seems like it should work, it does not. Sidestep this issue by matching an `tt`, i.e. any valid token tree. --- cursive-core/src/view/view_wrapper.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cursive-core/src/view/view_wrapper.rs b/cursive-core/src/view/view_wrapper.rs index 01b22ebf4..24567d596 100644 --- a/cursive-core/src/view/view_wrapper.rs +++ b/cursive-core/src/view/view_wrapper.rs @@ -157,11 +157,17 @@ impl View for T { /// impl ViewWrapper for FooView { /// cursive_core::wrap_impl!(self.view: T); /// } +/// +/// struct BarView(T); +/// +/// impl ViewWrapper for BarView { +/// cursive_core::wrap_impl!(self.0: T); +/// } /// # fn main() { } /// ``` #[macro_export] macro_rules! wrap_impl { - (self.$v:ident: $t:ty) => { + (self.$v:tt: $t:ty) => { type V = $t; fn with_view(&self, f: F) -> ::std::option::Option From b1a305235d533b4f55608f2a131e32aa1d75f683 Mon Sep 17 00:00:00 2001 From: Harrison McCullough Date: Sun, 12 Apr 2026 21:48:31 -0700 Subject: [PATCH 2/2] Add unit test for wrapping tuple struct with wrap_impl! --- cursive-core/src/view/view_wrapper.rs | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/cursive-core/src/view/view_wrapper.rs b/cursive-core/src/view/view_wrapper.rs index 24567d596..4cb69667f 100644 --- a/cursive-core/src/view/view_wrapper.rs +++ b/cursive-core/src/view/view_wrapper.rs @@ -231,3 +231,38 @@ macro_rules! inner_getters { } }; } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + #[allow(dead_code, unused_variables)] + fn standard_struct() { + struct FooView { + view: T, + enabled: bool, + } + + impl ViewWrapper for FooView { + wrap_impl!(self.view: T); + } + + let foo = FooView { + view: crate::views::TextView::new("Hello, World!"), + enabled: true, + }; + } + + #[test] + #[allow(dead_code, unused_variables)] + fn tuple_struct() { + struct BarView(T); + + impl ViewWrapper for BarView { + wrap_impl!(self.0: T); + } + + let bar = BarView(crate::views::TextView::new("Hello, World!")); + } +}