diff --git a/src/layout/id.rs b/src/layout/id.rs index 91c6241..99a78af 100644 --- a/src/layout/id.rs +++ b/src/layout/id.rs @@ -41,6 +41,7 @@ pub struct WidgetId { /// but they don't send drop messages to Ui. /// Ideally I'd have an enum or something that lets you use either, but that doesn't seem worth it /// right now; it's good enough and relatively cheap. +#[repr(C)] pub struct StaticWidgetId { pub(super) ty: TypeId, pub(super) id: CopyId, @@ -83,7 +84,7 @@ impl WidgetId { } pub fn as_any(&self) -> &WidgetId { - // safety: self is repr(C) and generic only used for phantom data + // SAFETY: self is repr(C) and generic only used for phantom data unsafe { std::mem::transmute(self) } } @@ -92,7 +93,7 @@ impl WidgetId { } pub(super) fn cast_type(self) -> WidgetId { - // safety: self is repr(C) and generic only used for phantom data + // SAFETY: self is repr(C) and generic only used for phantom data unsafe { std::mem::transmute(self) } } @@ -196,6 +197,7 @@ impl StaticWidgetId { WidgetId::new(self.id.id(), self.ty, send.clone(), true) } pub fn any(self) -> StaticWidgetId { + // SAFETY: self is repr(C) unsafe { std::mem::transmute(self) } } } diff --git a/src/layout/widgets.rs b/src/layout/widgets.rs index c985376..4fbbb3a 100644 --- a/src/layout/widgets.rs +++ b/src/layout/widgets.rs @@ -35,7 +35,7 @@ impl Widgets { /// get_dyn but dynamic borrow checking of widgets /// lets you do recursive (tree) operations, like the painter does pub fn get_dyn_dynamic(&self, id: &Id) -> WidgetWrapper<'_> { - // must guarantee no other mutable references to this widget exist + // SAFETY: must guarantee no other mutable references to this widget exist // done through the borrow variable let data: &mut WidgetData = unsafe { std::mem::transmute(self.map.get(id)) }; if data.borrowed {