I implement method trait with two params, but rust insist that I have only one:

Hello

I try to extend gtk component:

fn set_center_widget<P: IsA<gtk::Widget>>(&self, widget: Option<&P>) 
    {self.c.set_center_widget(widget)}

but it complain on:

error[E0049]: method `set_center_widget` has 1 type parameter but its trait declaration has 2 type parameters
  --> src/widget.rs:63:25
   |
63 |     fn set_center_widget<P: IsA<gtk::Widget>>(&self, widget: Option<&P>) 
   |                         ^^^^^^^^^^^^^^^^^^^^^ found 1 type parameter, expected 2

Thanks

If you don't show us the trait declaration, it'll be hard to help you...

The trait declaration is:

fn set_center_widget<P: IsA<Widget>>(&self, widget: Option<&P>);

from:
https://github.com/gtk-rs/gtk/blob/master/src/auto/box_.rs

Hmm, admittedly, that set_center_widget has only one type parameter... Could it be brought in scope from somewhere else? Another version of the gtk crate?

In the Cargo.toml I use:

[dependencies.gtk]
version = "0.6.0"
features = ["v3_16"]

but even in this version it is the same declaration:

fn set_center_widget<'a, P: IsA<Widget> + 'a, Q: Into<Option<&'a P>>>(&self, widget: Q);

https://github.com/gtk-rs/gtk/blob/0.6.0/src/auto/box_.rs

Are we looking at the same thing? I see 2 type parameters in the trait declaration:

 fn set_center_widget<'a, P: IsA<Widget> + 'a, Q: Into<Option<&'a P>>>(&self, widget: Q);

https://github.com/gtk-rs/gtk/blob/0.6.0/src/auto/box_.rs#L64

1 Like

Thanks! I looked only the

(&self, widget: Q)

part.

Glad I could help! :heart:

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.