Skip to main content

ferroui_controls/platform/
i_platform_handle.rs

1use std::any::Any;
2
3/// Represents a platform-specific handle.
4pub trait IPlatformHandle {
5    /// Gets the handle (a native pointer or identifier).
6    fn handle(&self) -> isize;
7
8    /// Gets an optional string that describes what `handle` represents.
9    fn handle_descriptor(&self) -> Option<&str>;
10
11    /// Lets backends recover the concrete handle type.
12    fn as_any(&self) -> &dyn Any;
13
14    /// Whether this handle is equal to `other`.
15    ///
16    /// The default is identity: a handle is only equal to itself. Value-like
17    /// handles (see [`PlatformHandle`](super::PlatformHandle)) compare their
18    /// contents.
19    fn equals(&self, other: &dyn IPlatformHandle) -> bool {
20        std::ptr::addr_eq(self as *const Self, other as *const dyn IPlatformHandle)
21    }
22
23    /// The handle as the handle of a native control that can be destroyed,
24    /// if it is one (C# `handle as INativeControlHostDestroyableControlHandle`).
25    /// An implementation of that contract returns itself.
26    fn as_native_control_host_destroyable_control_handle(
27        &self,
28    ) -> Option<&dyn super::INativeControlHostDestroyableControlHandle> {
29        None
30    }
31}