gtk-rs / gtk-rs-core

Rust bindings for GNOME libraries
https://gtk-rs.org/gtk-rs-core
MIT License
272 stars 105 forks source link

[BUG] not able to use the Property macro with a nested GEnum #1338

Open gdesmott opened 4 months ago

gdesmott commented 4 months ago

See this code trying to define a GEnum property inside a nested object. It fails, I think, because type = needs to be defined when using member = but I didn't find any way to make it work.

error[E0277]: the trait bound `std::sync::Mutex<foo::Inner>: Property` is not satisfied
   --> glib-macros/tests/properties.rs:159:13
    |
159 |             #[property(get, set, member = senum)]
    |             ^ the trait `Property` is not implemented for `std::sync::Mutex<foo::Inner>`
    |
    = help: the trait `Property` is implemented for `std::sync::Mutex<T>`

error[E0277]: the trait bound `std::sync::Mutex<foo::Inner>: Property` is not satisfied
  --> glib-macros/tests/properties.rs:90:18
   |
90 |         #[derive(Properties, Default)]
   |                  ^^^^^^^^^^ the trait `Property` is not implemented for `std::sync::Mutex<foo::Inner>`
   |
   = help: the trait `Property` is implemented for `std::sync::Mutex<T>`
   = note: this error originates in the derive macro `Properties` (in Nightly builds, run with -Z macro-backtrace for more info)
gdesmott commented 4 months ago

It seems to work when using a custom get implementation:

#[property(get = |t: &Self| t.inner_enum.lock().unwrap().senum.to_owned(), type = SimpleEnum, builder(SimpleEnum::One))]
inner_enum: Mutex<Inner>,
zecakeh commented 3 months ago

I tried with this, and it seems to work:

#[property(get, set, type = SimpleEnum, member = senum, builder(SimpleEnum::default()))]
inner_enum: Mutex<Inner>,
bilelmoussaoui commented 2 months ago

@gdesmott could you add a full reproducer of the issue please?

gdesmott commented 2 months ago

@gdesmott could you add a full reproducer of the issue please?

There is in this commit: https://github.com/gdesmott/gtk-rs-core/commit/f7d6a6049b44c298c56cbc1e4b6fb9ff218f46a9