From fc6912d4c0c5bc15e28499b7463cc10dc5b37058 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Tue, 23 Jan 2024 18:37:50 -0600 Subject: [PATCH] make GlobalMemo and GlobalSignal not copy or clone --- packages/signals/src/effect.rs | 2 +- packages/signals/src/impls.rs | 56 +++++++++++++++------------------- 2 files changed, 26 insertions(+), 32 deletions(-) diff --git a/packages/signals/src/effect.rs b/packages/signals/src/effect.rs index 2c12b7294..57a34fd29 100644 --- a/packages/signals/src/effect.rs +++ b/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)), }; diff --git a/packages/signals/src/impls.rs b/packages/signals/src/impls.rs index 25334f3be..aa6969fcf 100644 --- a/packages/signals/src/impls.rs +++ b/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 std::clone::Clone for $ty { - #[track_caller] - fn clone(&self) -> Self { - *self - } - } - - impl Copy for $ty {} - impl Display for $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, S: Storage>); write_impls!(CopyValue, Storage, Storage>); +impl> Clone for CopyValue { + fn clone(&self) -> Self { + *self + } +} + +impl> Copy for CopyValue {} + impl>> IntoIterator for CopyValue, S> { type IntoIter = ReadableValueIterator; @@ -139,6 +137,14 @@ impl>> IntoIterator for CopyValue, S> { read_impls!(Signal, S: Storage>, S: Storage>>); write_impls!(Signal, Storage>, Storage>>); +impl>> Clone for Signal { + fn clone(&self) -> Self { + *self + } +} + +impl>> Copy for Signal {} + impl>>> IntoIterator for Signal, S> { type IntoIter = ReadableValueIterator; @@ -155,6 +161,14 @@ read_impls!( S: Storage>> ); +impl>> Clone for ReadOnlySignal { + fn clone(&self) -> Self { + *self + } +} + +impl>> Copy for ReadOnlySignal {} + impl>>> IntoIterator for ReadOnlySignal, S> { type IntoIter = ReadableValueIterator; @@ -167,24 +181,4 @@ impl>>> IntoIterator for ReadOnlySignal read_impls!(GlobalSignal); -impl IntoIterator for GlobalSignal> { - type IntoIter = ReadableValueIterator; - - type Item = ::Ref; - - fn into_iter(self) -> Self::IntoIter { - self.iter() - } -} - read_impls!(GlobalMemo: PartialEq); - -impl IntoIterator for GlobalMemo> { - type IntoIter = ReadableValueIterator; - - type Item = ::Ref; - - fn into_iter(self) -> Self::IntoIter { - self.iter() - } -}