Hi there,
I am writing a generic WidgetPager
struct which needs to be able to show different widgets of different kinds. First I just used [gtk::Widget; N]
, the problem comes when gtk::Button != gtk::Widget
. Then I thought of using IsA<gtk::Widget>
since that's what the library uses internally.
It seems the trait IsA<>
is using Self
somewhere, or something inside it like ToGlibPtr
, which Rust doesn't accept to use safely.
Log:
error[E0038]: the trait `gtk4::prelude::IsA` cannot be made into an object
--> src/widgets/widget_pager.rs:5:17
|
5 | pages: [&'a IsA<gtk::Widget>; N],
| ^^^^^^^^^^^^^^^^ `gtk4::prelude::IsA` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> /home/aitor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/glib-0.20.0/src/object.rs:28:7
|
28 | + PartialEq
| ^^^^^^^^^ the trait cannot be made into an object because it uses `Self` as a type parameter
29 | + Eq
30 | + PartialOrd
| ^^^^^^^^^^ the trait cannot be made into an object because it uses `Self` as a type parameter
...
37 | + for<'a> ToGlibPtr<'a, *mut <Self as ObjectType>::GlibType>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait cannot be made into an object because it uses `Self` as a type parameter
38 | + IntoGlibPtr<*mut <Self as ObjectType>::GlibType>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait cannot be made into an object because it uses `Self` as a type parameter
|
::: /home/aitor/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/cmp.rs:329:15
|
329 | pub trait Eq: PartialEq<Self> {
| ^^^^^^^^^^^^^^^ the trait cannot be made into an object because it uses `Self` as a type parameter
...
822 | pub trait Ord: Eq + PartialOrd<Self> {
| ^^^^^^^^^^^^^^^^ the trait cannot be made into an object because it uses `Self` as a type parameter
error[E0308]: mismatched types
--> src/widgets/widget_pager.rs:39:13
|
14 | pub fn new(_pages: [&'a impl IsA<gtk::Widget>; N], active_page: Option<...
| --------------------- found this type parameter
...
39 | container_selected_page,
| ^^^^^^^^^^^^^^^^^^^^^^^ expected `&Widget`, found `&impl IsA<gtk::Widget>`
|
= note: expected reference `&'a gtk4::Widget`
found reference `&impl IsA<gtk::Widget>`
error[E0782]: trait objects must include the `dyn` keyword
--> src/widgets/widget_pager.rs:5:17
|
5 | pages: [&'a IsA<gtk::Widget>; N],
| ^^^^^^^^^^^^^^^^
|
help: add `dyn` keyword before this trait
|
5 | pages: [&'a dyn IsA<gtk::Widget>; N],
| +++