-
Notifications
You must be signed in to change notification settings - Fork 947
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
utils: implement AsAny only on OpaqueObject #4157
base: master
Are you sure you want to change the base?
Conversation
That ensures that the we cast to the right thing, since in some cases it was able to cast to wrapping container instead of the type that is wrapped. It's a bit annoying, but should help with random bugs. |
Given that `AsAny` was implemented for pretty much anything, it was really easy to use it on objects that were not really implementing AsAny.
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.
Hmm, I don't really see the value of this, so will neither "approve" nor "request changes" (if you're really blocked by this, then I'm fine with merging it).
The plan is to get rid of the platform
modules anyhow, right? When would you hit this otherwise? In user code? If so, then I'd rather expose something like the following:
impl dyn Window {
pub fn as_inner<T: 'static + Window>(&self) -> Option<&T> {
let this: &(dyn std::any::Any + '_) = self.as_any();
this.downcast_ref::<T>()
}
}
// Similarly for ActiveEventLoop, MonitorHandle, etc.
This is also a bit cleaner than the self.as_any().downcast_ref::<crate::platform_impl::Window>().unwrap()
that we do everywhere now, would simplify to self.as_inner::<crate::platform_impl::Window>().unwrap()
.
(I consider AsAny
a hack anyhow, and one that we'll be able to remove once we have MSRV 1.86, since by then rust-lang/rust#65991 will have landed).
The problem here is that It's mostly to not make a mistake in internal code, since |
I've opened #4160, I prefer that alternative. |
Given that
AsAny
was implemented for pretty much anything, it was really easy to use it on objects that were not really implementing AsAny.