-
-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gio: Add type parameter to ListModel and ListStore #609
base: main
Are you sure you want to change the base?
Conversation
Maybe there should still be a |
Wouldn't that be |
|
||
#[doc(alias = "g_list_model_get_object")] | ||
#[doc(alias = "get_object")] | ||
fn object(&self, position: u32) -> Option<Object>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the difference between get_item / get_object? i don't think we want to have both also it should probably return T maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There isn't any real difference in the C API besides the return type. I think fn object
can just be removed.
Returning T
is inconvenient because then you have to put <T>
on ListModelExt
and do ListModelExt::<Type>::object(&model, 123)
if you want to use the turbofish operator. Putting the parameter on fn item
lets you do model.item::<Type>(123)
. Sadly the return type always has to be specified if we want ListModel<T>
to be covariant on T
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason why get_item()
and get_object()
are separate is because get_item()
returns a void*
, whereas get_object()
returns a GObject*
. The initial design of GListModel was made generic enough to support any GType payload that could fit into a pointer. Of course, it's completely unbindable ex post, but every now and again somebody thinks they can outsmart every binding in existence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then perhaps fn object
should be kept, and item
removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think so, because bindings are supposed to use get_object internally and rename it to get_item; to be consistent with get_n_items
Not unless we want to relax |
20e01a4
to
2ca49d5
Compare
In GTK there are some we know the type of which could be implemented manually with a type parameter:
All the rest of the custom models should be safe to take a |
Unfortunately |
Fixes #213
This will break any autogenerated functions using
ListModel
but we could add a special rule in gir to change that toListModel<Object>
.Upcasting and downcasting works with a few rules:
ListModel<T>
is covariant onT
ListStore<T>
is invariant onT
ListStore<T>
are contravariant onT
I didn't really change subclassing, that still works the same except you have to do
type Interfaces = (gio::ListModel<MyType>,);
. There is a little bit more work that needs to be done if someone wants to do a generic object withtype Interfaces = (gio::ListModel<T>,);
, this PR not far off from that though.