fix subscriptions in events

This commit is contained in:
Evan Almloff committed 2023-08-04 17:23:57 -07:00
1 parent 07ed3e67dd
commit a6f611eccf
12 files changed
+445 -103

No files matched your search

+26 -8
View File
@@ -26,14 +26,6 @@ fn current_owner() -> Rc<Owner> {
}
}
impl<T> Copy for CopyValue<T> {}
impl<T> Clone for CopyValue<T> {
fn clone(&self) -> Self {
*self
}
}
pub struct CopyValue<T: 'static> {
pub value: CopyHandle<T>,
}
@@ -62,4 +54,30 @@ impl<T: 'static> CopyValue<T> {
pub fn write(&self) -> RefMut<'_, T> {
self.value.write()
}
pub fn set(&mut self, value: T) {
*self.write() = value;
}
pub fn with<O>(&self, f: impl FnOnce(&T) -> O) -> O {
let write = self.read();
f(&*write)
}
pub fn with_mut<O>(&self, f: impl FnOnce(&mut T) -> O) -> O {
let mut write = self.write();
f(&mut *write)
}
}
impl<T: Clone + 'static> CopyValue<T> {
pub fn value(&self) -> T {
self.read().clone()
}
}
impl<T: 'static> PartialEq for CopyValue<T> {
fn eq(&self, other: &Self) -> bool {
self.value.ptr_eq(&other.value)
}
}