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
[FEATURE REQUEST] downcast/upcast on Option<Object>
#842
Labels
enhancement
New feature or request
Comments
How about |
That's even longer than before |
// current
let label: gtk::Label = list_item.child().unwrap().downcast().unwrap();
// your solution
let label = list_item.child().and_then(|c| c.downcast::<gtk::Label>().ok()).unwrap()
// with downcast on Option<Object>
let label: gtk::Label = list_item.child().downcast().unwrap(); |
This is a duplicate of #497 |
I don't know, the |
ranfdev
added a commit
to ranfdev/gtk-rs-core
that referenced
this issue
Dec 1, 2022
Closes gtk-rs#842
Merged
bilelmoussaoui
pushed a commit
that referenced
this issue
Dec 4, 2022
* Add CastNone trait Closes #842 * Add CastNone to prelude, add dynamic_cast * Add example for CastNone * Describe type using turbofish op
bilelmoussaoui
pushed a commit
that referenced
this issue
Dec 5, 2022
* Add CastNone trait Closes #842 * Add CastNone to prelude, add dynamic_cast * Add example for CastNone * Describe type using turbofish op
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There are many cases where gtk returns an
Option<Widget>
which must be downcasted.Doing
let label: gtk::Label = list_item.child().unwrap().downcast().unwrap();
is not fun (note:child()
returnsOption<Widget>
).Implementing downcast and upcast for
Option<Widget>
would remove anunwrap
.I think it makes sense. In OOP languages you can have
null
objects, andnull
objects can be downcasted tonull
subclassess, can't they? (Edit: in Java you can upcast a null, but not downcast it. In any case, if we return a Result when downcasting, everything is alright)The text was updated successfully, but these errors were encountered: