SENSORS
This commit is contained in:
@@ -16,6 +16,7 @@ pub struct AnyWidget;
|
||||
///
|
||||
/// W does not need to implement widget so that AnyWidget is valid;
|
||||
/// Instead, add generic bounds on methods that take an ID if they need specific data.
|
||||
#[repr(C)]
|
||||
#[derive(Eq, Hash, PartialEq, Debug)]
|
||||
pub struct WidgetId<W = AnyWidget> {
|
||||
pub(super) ty: TypeId,
|
||||
@@ -38,10 +39,16 @@ impl<W> WidgetId<W> {
|
||||
_pd: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn erase_type(self) -> WidgetId<AnyWidget> {
|
||||
self.cast_type()
|
||||
}
|
||||
|
||||
pub fn as_any(&self) -> &WidgetId<AnyWidget> {
|
||||
// safety: self is repr(C) and generic only used for phantom data
|
||||
unsafe { std::mem::transmute(self) }
|
||||
}
|
||||
|
||||
fn cast_type<W2>(self) -> WidgetId<W2> {
|
||||
WidgetId {
|
||||
ty: self.ty,
|
||||
|
||||
Reference in New Issue
Block a user