trust + fix redraw bug

This commit is contained in:
2025-12-17 01:16:28 -05:00
parent 70ac0fbcb2
commit 7e6369029f
7 changed files with 38 additions and 32 deletions

View File

@@ -56,11 +56,6 @@ impl<State, W: ?Sized> WidgetHandle<State, W> {
}
}
pub fn as_any(&self) -> &WidgetHandle<State, dyn Widget<State>> {
// SAFETY: self is repr(C) and generic only used for phantom data
unsafe { std::mem::transmute(self) }
}
pub fn id(&self) -> WidgetId {
self.id
}

View File

@@ -1,6 +1,6 @@
use crate::{
IdLike, Widget, WidgetData, WidgetId,
util::{DynBorrower, HashSet, SlotVec},
util::{DynBorrower, HashSet, SlotVec, forget_mut, to_mut},
};
pub struct Widgets<State> {
@@ -36,12 +36,7 @@ impl<State: 'static> Widgets<State> {
pub(crate) fn get_dyn_dynamic<'a>(&self, id: WidgetId) -> WidgetWrapper<'a, State> {
// SAFETY: must guarantee no other mutable references to this widget exist
// done through the borrow variable
#[allow(mutable_transmutes)]
let data = unsafe {
std::mem::transmute::<&WidgetData<State>, &mut WidgetData<State>>(
self.vec.get(id).unwrap(),
)
};
let data = unsafe { forget_mut(to_mut(self.vec.get(id).unwrap())) };
if data.borrowed {
panic!("tried to mutably borrow the same widget twice");
}