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
|
|
@ -12,7 +12,7 @@ use crate::error::RequestError;
|
|||
pub use crate::icon::{BadIcon, Icon};
|
||||
use crate::monitor::{Fullscreen, MonitorHandle};
|
||||
use crate::platform_impl::PlatformSpecificWindowAttributes;
|
||||
use crate::utils::AsAny;
|
||||
use crate::utils::{impl_dyn_casting, AsAny};
|
||||
|
||||
/// Identifier of a window. Unique for each window.
|
||||
///
|
||||
|
|
@ -1335,7 +1335,7 @@ pub trait Window: AsAny + Send + Sync + fmt::Debug {
|
|||
fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle;
|
||||
}
|
||||
|
||||
impl dyn Window {
|
||||
impl dyn Window + '_ {
|
||||
/// Create a new [`WindowAttributes`] which allows modifying the window's attributes before
|
||||
/// creation.
|
||||
pub fn default_attributes() -> WindowAttributes {
|
||||
|
|
@ -1343,6 +1343,8 @@ impl dyn Window {
|
|||
}
|
||||
}
|
||||
|
||||
impl_dyn_casting!(Window);
|
||||
|
||||
impl PartialEq for dyn Window + '_ {
|
||||
fn eq(&self, other: &dyn Window) -> bool {
|
||||
self.id().eq(&other.id())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue