1
0
Эх сурвалжийг харах

make GlobalMemo and GlobalSignal not copy or clone

Evan Almloff 1 жил өмнө
parent
commit
fc6912d4c0

+ 1 - 1
packages/signals/src/effect.rs

@@ -127,7 +127,7 @@ impl Effect {
     ///
     /// The signal will be owned by the current component and will be dropped when the component is dropped.
     pub fn new(callback: impl FnMut() + 'static) -> Self {
-        let mut myself = Self {
+        let myself = Self {
             source: current_scope_id().expect("in a virtual dom"),
             inner: EffectInner::new(Box::new(callback)),
         };

+ 25 - 31
packages/signals/src/impls.rs

@@ -4,8 +4,7 @@ use crate::rt::CopyValue;
 use crate::signal::Signal;
 use crate::write::Writable;
 use crate::{GlobalMemo, GlobalSignal, ReadOnlySignal, ReadableValueIterator, SignalData};
-use generational_box::UnsyncStorage;
-use generational_box::{AnyStorage, Storage};
+use generational_box::Storage;
 
 use std::{
     fmt::{Debug, Display},
@@ -23,15 +22,6 @@ macro_rules! read_impls {
             }
         )?
 
-        impl<T $(: $extra_bounds)? $(,$bound_ty: $bound)?> std::clone::Clone for $ty<T $(, $bound_ty)?> {
-            #[track_caller]
-            fn clone(&self) -> Self {
-                *self
-            }
-        }
-
-        impl<T $(: $extra_bounds)? $(,$bound_ty: $bound)?> Copy for $ty<T $(, $bound_ty)?> {}
-
         impl<T: $($extra_bounds + )? Display + 'static $(,$bound_ty: $bound)?> Display for $ty<T $(, $bound_ty)?> {
             #[track_caller]
             fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
@@ -126,6 +116,14 @@ macro_rules! write_impls {
 read_impls!(CopyValue, S: Storage<T>, S: Storage<Vec<T>>);
 write_impls!(CopyValue, Storage<T>, Storage<Vec<T>>);
 
+impl<T: 'static, S: Storage<T>> Clone for CopyValue<T, S> {
+    fn clone(&self) -> Self {
+        *self
+    }
+}
+
+impl<T: 'static, S: Storage<T>> Copy for CopyValue<T, S> {}
+
 impl<T: 'static, S: Storage<Vec<T>>> IntoIterator for CopyValue<Vec<T>, S> {
     type IntoIter = ReadableValueIterator<T, Self>;
 
@@ -139,6 +137,14 @@ impl<T: 'static, S: Storage<Vec<T>>> IntoIterator for CopyValue<Vec<T>, S> {
 read_impls!(Signal, S: Storage<SignalData<T>>, S: Storage<SignalData<Vec<T>>>);
 write_impls!(Signal, Storage<SignalData<T>>, Storage<SignalData<Vec<T>>>);
 
+impl<T: 'static, S: Storage<SignalData<T>>> Clone for Signal<T, S> {
+    fn clone(&self) -> Self {
+        *self
+    }
+}
+
+impl<T: 'static, S: Storage<SignalData<T>>> Copy for Signal<T, S> {}
+
 impl<T: 'static, S: Storage<SignalData<Vec<T>>>> IntoIterator for Signal<Vec<T>, S> {
     type IntoIter = ReadableValueIterator<T, Self>;
 
@@ -155,36 +161,24 @@ read_impls!(
     S: Storage<SignalData<Vec<T>>>
 );
 
-impl<T: 'static, S: Storage<SignalData<Vec<T>>>> IntoIterator for ReadOnlySignal<Vec<T>, S> {
-    type IntoIter = ReadableValueIterator<T, Self>;
-
-    type Item = S::Ref<T>;
-
-    fn into_iter(self) -> Self::IntoIter {
-        self.iter()
+impl<T: 'static, S: Storage<SignalData<T>>> Clone for ReadOnlySignal<T, S> {
+    fn clone(&self) -> Self {
+        *self
     }
 }
 
-read_impls!(GlobalSignal);
+impl<T: 'static, S: Storage<SignalData<T>>> Copy for ReadOnlySignal<T, S> {}
 
-impl<T: 'static> IntoIterator for GlobalSignal<Vec<T>> {
+impl<T: 'static, S: Storage<SignalData<Vec<T>>>> IntoIterator for ReadOnlySignal<Vec<T>, S> {
     type IntoIter = ReadableValueIterator<T, Self>;
 
-    type Item = <UnsyncStorage as AnyStorage>::Ref<T>;
+    type Item = S::Ref<T>;
 
     fn into_iter(self) -> Self::IntoIter {
         self.iter()
     }
 }
 
-read_impls!(GlobalMemo: PartialEq);
-
-impl<T: PartialEq + 'static> IntoIterator for GlobalMemo<Vec<T>> {
-    type IntoIter = ReadableValueIterator<T, Self>;
-
-    type Item = <UnsyncStorage as AnyStorage>::Ref<T>;
+read_impls!(GlobalSignal);
 
-    fn into_iter(self) -> Self::IntoIter {
-        self.iter()
-    }
-}
+read_impls!(GlobalMemo: PartialEq);