Skip to content
This repository was archived by the owner on Mar 4, 2024. It is now read-only.
This repository was archived by the owner on Mar 4, 2024. It is now read-only.

Unable to use item method from ListModel  #478

@haecker-felix

Description

@haecker-felix

error message

error[E0599]: no method named `item` found for reference `&torrent_model::TrTorrentModel` in the current scope
  --> src/transmission-gobject/src/torrent_model.rs:82:18
   |
82 |             self.item(index)
   |                  ^^^^ method not found in `&torrent_model::TrTorrentModel`
   |
   = help: items from traits can only be used if the trait is implemented and in scope
   = note: the following trait defines an item `item`, perhaps you need to implement it:
           candidate #1: `gio::subclass::prelude::ListModelImpl`

Interesting is, that I can use other methods from ListModel like n_items, but not item

relevant code snippets:

    #[glib::object_subclass]
    impl ObjectSubclass for TrTorrentModel {
        const NAME: &'static str = "TrTorrentModel";
        type ParentType = glib::Object;
        type Type = super::TrTorrentModel;
        type Interfaces = (gio::ListModel,);
    }

    impl ObjectImpl for TrTorrentModel {}

    impl ListModelImpl for TrTorrentModel {
        fn item_type(&self, _list_model: &Self::Type) -> glib::Type {
            TrTorrent::static_type()
        }
        fn n_items(&self, _list_model: &Self::Type) -> u32 {
            self.vec.borrow().len() as u32
        }
        fn item(&self, _list_model: &Self::Type, position: u32) -> Option<glib::Object> {
            self.vec
                .borrow()
                .get(position as usize)
                .map(|o| o.clone().upcast::<glib::Object>())
        }
    }
glib::wrapper! {
    pub struct TrTorrentModel(ObjectSubclass<imp::TrTorrentModel>) @implements gio::ListModel;
}

complete code: https://pastebin.com/gmFra9Qh

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions