Support generic types in glib::object_subclass#1286
Support generic types in glib::object_subclass#1286andy128k wants to merge 1 commit intogtk-rs:mainfrom
glib::object_subclass#1286Conversation
|
What would be the use case here? |
|
Well, code reuse. Let's say, I want to write a generic widget once and re-use it in a different contexts. |
sdroege
left a comment
There was a problem hiding this comment.
Can you add some tests to actually make use of this at runtime and make sure the types work correctly?
| .. | ||
| } = input; | ||
|
|
||
| let self_ty_as_ident = match &**self_ty { |
There was a problem hiding this comment.
I didn't look too close but I think this is currently unsound. There's only a single type registered for every T, so you can currently safely cast between different T. Not sure how that can be solved nicely.
There was a problem hiding this comment.
Yep, single type. Similar to generics in Java with type erasure.
There was a problem hiding this comment.
Unlike in Java this is unsound here though :) In the simplest case, you could have a MyObj<T> that stores a T, and then simply casting that between T: String to T: u32 and the subclass couldn't know about that happening and accesses the value with the wrong type then.
Support generic types in
glib::object_subclassandglib::object_interfacemacros.