From 5f9e5f607b94aa92cd90584a97bb1c1b28198963 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Fri, 8 Mar 2024 10:35:27 -0600 Subject: [PATCH] rename take to manually drop --- packages/generational-box/src/lib.rs | 4 ++-- packages/signals/src/copy_value.rs | 8 +++----- packages/signals/src/read_only_signal.rs | 4 +++- packages/signals/src/signal.rs | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/generational-box/src/lib.rs b/packages/generational-box/src/lib.rs index 296e1741c..f933514d5 100644 --- a/packages/generational-box/src/lib.rs +++ b/packages/generational-box/src/lib.rs @@ -186,8 +186,8 @@ impl> GenerationalBox { } } - /// Take the value out of the generational box and invalidate the generational box. This will return the value if the value was taken. - pub fn take(&self) -> Option { + /// Drop the value out of the generational box and invalidate the generational box. This will return the value if the value was taken. + pub fn manually_drop(&self) -> Option { if self.validate() { Storage::take(&self.raw.0.data) } else { diff --git a/packages/signals/src/copy_value.rs b/packages/signals/src/copy_value.rs index ac0fc0805..5dbf41a3c 100644 --- a/packages/signals/src/copy_value.rs +++ b/packages/signals/src/copy_value.rs @@ -190,11 +190,9 @@ impl> CopyValue { } } - /// Take the value out of the CopyValue, invalidating the value in the process. - pub fn take(&self) -> T { - self.value - .take() - .expect("value is already dropped or borrowed") + /// Manually drop the value in the CopyValue, invalidating the value in the process. + pub fn manually_drop(&self) -> Option { + self.value.manually_drop() } /// Get the scope this value was created in. diff --git a/packages/signals/src/read_only_signal.rs b/packages/signals/src/read_only_signal.rs index 26e7730c6..618049eb1 100644 --- a/packages/signals/src/read_only_signal.rs +++ b/packages/signals/src/read_only_signal.rs @@ -50,7 +50,9 @@ impl>> ReadOnlySignal { #[doc(hidden)] /// This should only be used by the `rsx!` macro. pub fn __take(&self) -> T { - self.inner.take() + self.inner + .manually_drop() + .expect("Signal has already been dropped") } } diff --git a/packages/signals/src/signal.rs b/packages/signals/src/signal.rs index aa65f60fd..2708b7b4f 100644 --- a/packages/signals/src/signal.rs +++ b/packages/signals/src/signal.rs @@ -136,9 +136,9 @@ impl>> Signal { } } - /// Take the value out of the signal, invalidating the signal in the process. - pub fn take(&self) -> T { - self.inner.take().value + /// Drop the value out of the signal, invalidating the signal in the process. + pub fn manually_drop(&self) -> Option { + self.inner.manually_drop().map(|i| i.value) } /// Get the scope the signal was created in.