diff --git a/cursive-core/src/view/view_wrapper.rs b/cursive-core/src/view/view_wrapper.rs index 01b22ebf..4cb69667 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 @@ -225,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!")); + } +}