Don't understand the compiler's message

Hello everyone,
I'm relatively new to rust and I'm trying to learn it by doing a simple project in it. I'm using gtk4 bindings for rust.

column_view: gtk::ColumnView = /*inited*/

column_view.connect_activate(|col_view, inx| {
            let ss_mod: gtk::SelectionModel = col_view.model().unwrap();//works
            let selected_item: gio::ListModel = ss_mod.model();//here I'm getting error
        });

The error:

the method model exists for struct SelectionModel, but its trait bounds were not satisfied

And what is strange to me that when I check the gtk::SelectionModel, there I can find the model method. So I really don't understand why I cannot call it?

Any help appreciated.
Thank you

I can't find it in the docs. Can you link it?

I'm sorry, there is some mistake on my part. Now that I tried to find that method in code so I could post screenshot I cannot find it.
OK, I got it, the method model is in SingleSelection type.

So, just to make sure that I understand what that compiler msg means. I understand it as the trait has not been defined for that type, is that correct?

The specific compiler error you ran in to can be pretty bad sometimes. It will occasionally say that the method exists but trait bounds were not satisfied even though the method really just doesn't exist at all for that type.

Thank you for the answer.
Here is another problem of the same type (last line, I've also pasted a screenshot to show that the set_file method indeed is there):

 list_view.connect_activate(|col_view, inx| {
            println!("ColumnViewClicked:{},{}", col_view, inx);
            let ss_mod: gtk::SingleSelection = col_view
                .model()
                .unwrap()
                .downcast::<gtk::SingleSelection>()
                .unwrap();
            let list_model: gio::ListModel = ss_mod.model();
            let sm = list_model.downcast::<gtk::SortListModel>().unwrap();
            <gtk::SortListModel as gtk::DirectoryList>::set_file(sm, "a");
        });

I don't see the set_file method you mention anywhere on the documentation for gtk4::SortListModel.

The set_file method is in DirectoryList, see screenshot:

I'm confused about the <gtk::SortListModel as gtk::DirectoryList> syntax here. This usually requires that the right-hand-side is a trait, but DirectoryList is a struct. As a quick check, this fails in a similar way:

struct A {}
struct B {}

impl B {
    fn foo() {}
}

fn foo() {
    <A as B>::foo();
}

You probably need to figure out how gtk wants you to do downcasting.

Hi and sorry for the late reply.
The point is that DirectoryList IS a ListModel.
The problem I'm having is that after getting the model (the ListModel) from:

let list_model: gio::ListModel = ss_mod.model();

But this^^^ model is in fact gtk::DirectoryList. The question is how to access that interface?

You're probably looking for glib::object::Cast.

Thank you, that indeed did the trick!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.