and mut bound to mut methods on signals

This commit is contained in:
Jonathan Kelley committed 2024-01-15 23:24:59 -08:00
1 parent f1596bf5e8
commit 8559984e9d
31 files changed
+129 -153

No files matched your search

+7 -3
View File
@@ -151,6 +151,10 @@ impl<T: 'static> CopyValue<T> {
self.value.try_write()
}
pub fn write_unchecked(&self) -> GenerationalRefMut<T> {
self.value.write()
}
/// Write the value. If the value has been dropped, this will panic.
#[track_caller]
pub fn write(&self) -> GenerationalRefMut<T> {
@@ -188,8 +192,8 @@ impl<T: 'static> PartialEq for CopyValue<T> {
}
}
impl<T> Deref for CopyValue<T> {
type Target = dyn Fn() -> GenerationalRef<T>;
impl<T: 'static + Clone> Deref for CopyValue<T> {
type Target = dyn Fn() -> T;
fn deref(&self) -> &Self::Target {
// https://github.com/dtolnay/case-studies/tree/master/callable-types
@@ -197,7 +201,7 @@ impl<T> Deref for CopyValue<T> {
// First we create a closure that captures something with the Same in memory layout as Self (MaybeUninit<Self>).
let uninit_callable = MaybeUninit::<Self>::uninit();
// Then move that value into the closure. We assume that the closure now has a in memory layout of Self.
let uninit_closure = move || Self::read(unsafe { &*uninit_callable.as_ptr() });
let uninit_closure = move || Self::read(unsafe { &*uninit_callable.as_ptr() }).clone();
// Check that the size of the closure is the same as the size of Self in case the compiler changed the layout of the closure.
let size_of_closure = std::mem::size_of_val(&uninit_closure);