utils: add cast_* methods to allow more type-safe casting
Relying on just `as_any` was error prone and will become redundant in the future, once upcasting will be stable, we also won't to impose a restriction on to which concrete type we're casting, since casting to a type that doesn't implement a base trait doesn't make much sense. Co-authored-by: Kirill Chibisov <contact@kchibisov.com>
This commit is contained in:
parent
5cada36ae8
commit
16d5f46db1
19 changed files with 158 additions and 136 deletions
|
|
@ -101,20 +101,19 @@ pub trait WindowExtAndroid {
|
|||
|
||||
impl WindowExtAndroid for dyn Window + '_ {
|
||||
fn content_rect(&self) -> Rect {
|
||||
let window = self.as_any().downcast_ref::<crate::platform_impl::Window>().unwrap();
|
||||
let window = self.cast_ref::<crate::platform_impl::Window>().unwrap();
|
||||
window.content_rect()
|
||||
}
|
||||
|
||||
fn config(&self) -> ConfigurationRef {
|
||||
let window = self.as_any().downcast_ref::<crate::platform_impl::Window>().unwrap();
|
||||
let window = self.cast_ref::<crate::platform_impl::Window>().unwrap();
|
||||
window.config()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveEventLoopExtAndroid for dyn ActiveEventLoop + '_ {
|
||||
fn android_app(&self) -> &AndroidApp {
|
||||
let event_loop =
|
||||
self.as_any().downcast_ref::<crate::platform_impl::ActiveEventLoop>().unwrap();
|
||||
let event_loop = self.cast_ref::<crate::platform_impl::ActiveEventLoop>().unwrap();
|
||||
&event_loop.app
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue