From f2e48f10e9bc397dabd70e39c6db745ef436eb97 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Tue, 23 Jan 2024 18:46:24 -0600 Subject: [PATCH] simplify the crm example a bit more --- examples/crm.rs | 2 +- packages/signals/src/impls.rs | 33 +-------------------------------- packages/signals/src/read.rs | 12 ++++++------ packages/signals/src/write.rs | 2 +- 4 files changed, 9 insertions(+), 40 deletions(-) diff --git a/examples/crm.rs b/examples/crm.rs index 564b7e0c9..fe7c3f276 100644 --- a/examples/crm.rs +++ b/examples/crm.rs @@ -51,7 +51,7 @@ fn ClientList() -> Element { h2 { "List of Clients" } Link { to: Route::ClientAdd, class: "pure-button pure-button-primary", "Add Client" } Link { to: Route::Settings, class: "pure-button", "Settings" } - for client in CLIENTS.read().iter() { + for client in CLIENTS.iter() { div { class: "client", style: "margin-bottom: 50px", p { "Name: {client.first_name} {client.last_name}" } p { "Description: {client.description}" } diff --git a/packages/signals/src/impls.rs b/packages/signals/src/impls.rs index aa6969fcf..6c159e677 100644 --- a/packages/signals/src/impls.rs +++ b/packages/signals/src/impls.rs @@ -1,9 +1,8 @@ use crate::read::Readable; -use crate::read::ReadableVecExt; use crate::rt::CopyValue; use crate::signal::Signal; use crate::write::Writable; -use crate::{GlobalMemo, GlobalSignal, ReadOnlySignal, ReadableValueIterator, SignalData}; +use crate::{GlobalMemo, GlobalSignal, ReadOnlySignal, SignalData}; use generational_box::Storage; use std::{ @@ -124,16 +123,6 @@ impl> Clone for CopyValue { impl> Copy for CopyValue {} -impl>> IntoIterator for CopyValue, S> { - type IntoIter = ReadableValueIterator; - - type Item = S::Ref; - - fn into_iter(self) -> Self::IntoIter { - self.iter() - } -} - read_impls!(Signal, S: Storage>, S: Storage>>); write_impls!(Signal, Storage>, Storage>>); @@ -145,16 +134,6 @@ impl>> Clone for Signal { impl>> Copy for Signal {} -impl>>> IntoIterator for Signal, S> { - type IntoIter = ReadableValueIterator; - - type Item = S::Ref; - - fn into_iter(self) -> Self::IntoIter { - self.iter() - } -} - read_impls!( ReadOnlySignal, S: Storage>, @@ -169,16 +148,6 @@ impl>> Clone for ReadOnlySignal { impl>> Copy for ReadOnlySignal {} -impl>>> IntoIterator for ReadOnlySignal, S> { - type IntoIter = ReadableValueIterator; - - type Item = S::Ref; - - fn into_iter(self) -> Self::IntoIter { - self.iter() - } -} - read_impls!(GlobalSignal); read_impls!(GlobalMemo: PartialEq); diff --git a/packages/signals/src/read.rs b/packages/signals/src/read.rs index cbf543520..fa308210d 100644 --- a/packages/signals/src/read.rs +++ b/packages/signals/src/read.rs @@ -85,26 +85,26 @@ pub trait ReadableVecExt: Readable> { /// Get an iterator over the values of the inner vector. #[track_caller] - fn iter(&self) -> ReadableValueIterator + fn iter(&self) -> ReadableValueIterator<'_, T, Self> where - Self: Sized + Clone, + Self: Sized, { ReadableValueIterator { index: 0, - value: self.clone(), + value: self, phantom: std::marker::PhantomData, } } } /// An iterator over the values of a `Readable>`. -pub struct ReadableValueIterator { +pub struct ReadableValueIterator<'a, T, R> { index: usize, - value: R, + value: &'a R, phantom: std::marker::PhantomData, } -impl>> Iterator for ReadableValueIterator { +impl<'a, T: 'static, R: Readable>> Iterator for ReadableValueIterator<'a, T, R> { type Item = R::Ref; fn next(&mut self) -> Option { diff --git a/packages/signals/src/write.rs b/packages/signals/src/write.rs index bc448cf90..93f2ef42d 100644 --- a/packages/signals/src/write.rs +++ b/packages/signals/src/write.rs @@ -175,7 +175,7 @@ pub trait WritableVecExt: Writable> { /// Gets an iterator over the values of the vector. #[track_caller] - fn iter(&self) -> WritableValueIterator + fn iter_mut(&self) -> WritableValueIterator where Self: Sized + Clone, {