From 94c0c2e5b916ee6f35f398eb0bbb128ae20190c4 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Tue, 23 Jan 2024 11:29:13 -0600 Subject: [PATCH] remove some old manual implementations of helpers --- packages/router/src/contexts/router.rs | 2 +- packages/signals/src/impls.rs | 73 +++++++++++++++----------- packages/signals/src/signal.rs | 2 + 3 files changed, 44 insertions(+), 33 deletions(-) diff --git a/packages/router/src/contexts/router.rs b/packages/router/src/contexts/router.rs index 6d4a45b30..7c1ee5180 100644 --- a/packages/router/src/contexts/router.rs +++ b/packages/router/src/contexts/router.rs @@ -293,7 +293,7 @@ impl RouterContext { fn change_route(&self) -> Option { let self_read = self.inner.read(); if let Some(callback) = &self_read.routing_callback { - let myself = self.clone(); + let myself = *self; let callback = callback.clone(); drop(self_read); if let Some(new) = callback(myself) { diff --git a/packages/signals/src/impls.rs b/packages/signals/src/impls.rs index 12d11d21e..1c648883a 100644 --- a/packages/signals/src/impls.rs +++ b/packages/signals/src/impls.rs @@ -1,13 +1,12 @@ use crate::read::Readable; use crate::read::ReadableVecExt; use crate::rt::CopyValue; -use crate::signal::{Signal, Write}; +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::{GenerationalRef, UnsyncStorage}; -use std::cell::Ref; use std::{ fmt::{Debug, Display}, ops::{Add, Div, Mul, Sub}, @@ -141,25 +140,6 @@ macro_rules! write_impls { read_impls!(CopyValue, S: Storage, S: Storage>); write_impls!(CopyValue, Storage, Storage>); -read_impls!(Signal, S: Storage>, S: Storage>>); -write_impls!(Signal, Storage>, Storage>>); - -read_impls!( - ReadOnlySignal, - S: Storage>, - S: Storage>> -); - -read_impls!(GlobalSignal); -read_impls!(GlobalMemo: PartialEq); - -impl GlobalMemo> { - /// Read a value from the inner vector. - pub fn get(&'static self, index: usize) -> Option>> { - ::try_map(self.read(), move |v| v.get(index)) - } -} - impl>> IntoIterator for CopyValue, S> { type IntoIter = ReadableValueIterator; @@ -170,12 +150,8 @@ impl>> IntoIterator for CopyValue, S> { } } -impl>> CopyValue, S> { - /// Deref the inner value mutably. - pub fn as_mut(&self) -> Option> { - S::try_map_mut(self.write(), |v: &mut Option| v.as_mut()) - } -} +read_impls!(Signal, S: Storage>, S: Storage>>); +write_impls!(Signal, Storage>, Storage>>); impl>>> IntoIterator for Signal, S> { type IntoIter = ReadableValueIterator; @@ -187,9 +163,42 @@ impl>>> IntoIterator for Signal, } } -impl>>> Signal, S> { - /// Returns a reference to an element or `None` if out of bounds. - pub fn as_mut(&mut self) -> Option> { - Write::filter_map(self.write(), |v| v.as_mut()) +read_impls!( + ReadOnlySignal, + S: Storage>, + S: Storage>> +); + +impl>>> IntoIterator for ReadOnlySignal, S> { + type IntoIter = ReadableValueIterator; + + type Item = S::Ref; + + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} + +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() } } diff --git a/packages/signals/src/signal.rs b/packages/signals/src/signal.rs index d1f58662d..ee31e56fc 100644 --- a/packages/signals/src/signal.rs +++ b/packages/signals/src/signal.rs @@ -228,6 +228,7 @@ impl Signal { } /// Creates a new global Signal that can be used in a global static. + #[track_caller] pub const fn global(constructor: fn() -> T) -> GlobalSignal { GlobalSignal::new(constructor) } @@ -235,6 +236,7 @@ impl Signal { impl Signal { /// Creates a new global Signal that can be used in a global static. + #[track_caller] pub const fn global_memo(constructor: fn() -> T) -> GlobalMemo where T: PartialEq,