Pārlūkot izejas kodu

remove some old manual implementations of helpers

Evan Almloff 1 gadu atpakaļ
vecāks
revīzija
94c0c2e5b9

+ 1 - 1
packages/router/src/contexts/router.rs

@@ -293,7 +293,7 @@ impl RouterContext {
     fn change_route(&self) -> Option<ExternalNavigationFailure> {
         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) {

+ 35 - 26
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,26 +140,36 @@ 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<Vec<T>>> IntoIterator for CopyValue<Vec<T>, S> {
+    type IntoIter = ReadableValueIterator<T, Self>;
+
+    type Item = S::Ref<T>;
+
+    fn into_iter(self) -> Self::IntoIter {
+        self.iter()
+    }
+}
+
 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<Vec<T>>>> IntoIterator for Signal<Vec<T>, S> {
+    type IntoIter = ReadableValueIterator<T, Self>;
+
+    type Item = S::Ref<T>;
+
+    fn into_iter(self) -> Self::IntoIter {
+        self.iter()
+    }
+}
+
 read_impls!(
     ReadOnlySignal,
     S: Storage<SignalData<T>>,
     S: Storage<SignalData<Vec<T>>>
 );
 
-read_impls!(GlobalSignal);
-read_impls!(GlobalMemo: PartialEq);
-
-impl<T: PartialEq + 'static> GlobalMemo<Vec<T>> {
-    /// Read a value from the inner vector.
-    pub fn get(&'static self, index: usize) -> Option<GenerationalRef<Ref<'static, T>>> {
-        <UnsyncStorage as AnyStorage>::try_map(self.read(), move |v| v.get(index))
-    }
-}
-
-impl<T: 'static, S: Storage<Vec<T>>> IntoIterator for CopyValue<Vec<T>, S> {
+impl<T: 'static, S: Storage<SignalData<Vec<T>>>> IntoIterator for ReadOnlySignal<Vec<T>, S> {
     type IntoIter = ReadableValueIterator<T, Self>;
 
     type Item = S::Ref<T>;
@@ -170,26 +179,26 @@ impl<T: 'static, S: Storage<Vec<T>>> IntoIterator for CopyValue<Vec<T>, S> {
     }
 }
 
-impl<T: 'static, S: Storage<Option<T>>> CopyValue<Option<T>, S> {
-    /// Deref the inner value mutably.
-    pub fn as_mut(&self) -> Option<S::Mut<T>> {
-        S::try_map_mut(self.write(), |v: &mut Option<T>| v.as_mut())
-    }
-}
+read_impls!(GlobalSignal);
 
-impl<T: 'static, S: Storage<SignalData<Vec<T>>>> IntoIterator for Signal<Vec<T>, S> {
+impl<T: 'static> IntoIterator for GlobalSignal<Vec<T>> {
     type IntoIter = ReadableValueIterator<T, Self>;
 
-    type Item = S::Ref<T>;
+    type Item = <UnsyncStorage as AnyStorage>::Ref<T>;
 
     fn into_iter(self) -> Self::IntoIter {
         self.iter()
     }
 }
 
-impl<T: 'static, S: Storage<SignalData<Option<T>>>> Signal<Option<T>, S> {
-    /// Returns a reference to an element or `None` if out of bounds.
-    pub fn as_mut(&mut self) -> Option<Write<T, S>> {
-        Write::filter_map(self.write(), |v| v.as_mut())
+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>;
+
+    fn into_iter(self) -> Self::IntoIter {
+        self.iter()
     }
 }

+ 2 - 0
packages/signals/src/signal.rs

@@ -228,6 +228,7 @@ impl<T: 'static> Signal<T> {
     }
 
     /// Creates a new global Signal that can be used in a global static.
+    #[track_caller]
     pub const fn global(constructor: fn() -> T) -> GlobalSignal<T> {
         GlobalSignal::new(constructor)
     }
@@ -235,6 +236,7 @@ impl<T: 'static> Signal<T> {
 
 impl<T: PartialEq + 'static> Signal<T> {
     /// Creates a new global Signal that can be used in a global static.
+    #[track_caller]
     pub const fn global_memo(constructor: fn() -> T) -> GlobalMemo<T>
     where
         T: PartialEq,