Skip to content

Commit

Permalink
Align Hash impl with PartialEq
Browse files Browse the repository at this point in the history
  • Loading branch information
Giovanni-Tably committed Feb 23, 2024
1 parent c37b045 commit f658d6a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
22 changes: 10 additions & 12 deletions leptos_reactive/src/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,10 +789,9 @@ impl<T: PartialEq> PartialEq for ReadSignal<T> {
}
}

impl<T> Hash for ReadSignal<T> {
impl<T: Hash> Hash for ReadSignal<T> {
fn hash<H: Hasher>(&self, state: &mut H) {
Runtime::current().hash(state);
self.id.hash(state);
self.with(|v| v.hash(state));
}
}

Expand Down Expand Up @@ -1111,12 +1110,12 @@ impl<T> fmt::Debug for WriteSignal<T> {
// }
// }

impl<T> Hash for WriteSignal<T> {
fn hash<H: Hasher>(&self, state: &mut H) {
Runtime::current().hash(state);
self.id.hash(state);
}
}
// impl<T> Hash for WriteSignal<T> {
// fn hash<H: Hasher>(&self, state: &mut H) {
// Runtime::current().hash(state);
// self.id.hash(state);
// }
// }

/// Creates a reactive signal with the getter and setter unified in one value.
/// You may prefer this style, or it may be easier to pass around in a context
Expand Down Expand Up @@ -1238,10 +1237,9 @@ impl<T: PartialEq> PartialEq for RwSignal<T> {
}
}

impl<T> Hash for RwSignal<T> {
impl<T: Hash> Hash for RwSignal<T> {
fn hash<H: Hasher>(&self, state: &mut H) {
Runtime::current().hash(state);
self.id.hash(state);
self.with(|v| v.hash(state));
}
}

Expand Down
13 changes: 6 additions & 7 deletions leptos_reactive/src/signal_ext.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
create_rw_signal, store_value, Runtime, RwSignal, Scope, Signal,
SignalDispose, SignalGet, SignalGetUntracked, SignalSet, SignalUpdate,
SignalWith, SignalWithUntracked,
create_rw_signal, store_value, RwSignal, Scope, Signal, SignalDispose,
SignalGet, SignalGetUntracked, SignalSet, SignalUpdate, SignalWith,
SignalWithUntracked,
};
use std::{
hash::{Hash, Hasher},
Expand Down Expand Up @@ -33,10 +33,9 @@ impl<T: 'static> Clone for LeakedRwSignal<T> {
Self(self.0)
}
}
impl<T: 'static> Hash for LeakedRwSignal<T> {
impl<T: Hash + 'static> Hash for LeakedRwSignal<T> {
fn hash<H: Hasher>(&self, state: &mut H) {
Runtime::current().hash(state);
self.id.hash(state);
self.with(|v| v.hash(state));
}
}
impl<T: 'static> Deref for LeakedRwSignal<T> {
Expand Down Expand Up @@ -91,7 +90,7 @@ impl<T: 'static> Clone for RcSignal<T> {
}
}
}
impl<T: 'static> Hash for RcSignal<T> {
impl<T: Hash + 'static> Hash for RcSignal<T> {
fn hash<H: Hasher>(&self, state: &mut H) {
self.inner.0.hash(state);
}
Expand Down
7 changes: 3 additions & 4 deletions leptos_reactive/src/stored_value.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{with_runtime, Runtime, ScopeProperty};
use crate::{with_runtime, ScopeProperty};
use std::{
cell::RefCell,
fmt,
Expand Down Expand Up @@ -60,10 +60,9 @@ impl<T> PartialEq for StoredValue<T> {
}
}

impl<T> Hash for StoredValue<T> {
impl<T: Hash> Hash for StoredValue<T> {
fn hash<H: Hasher>(&self, state: &mut H) {
Runtime::current().hash(state);
self.id.hash(state);
self.with_value(|v| v.hash(state));
}
}

Expand Down

0 comments on commit f658d6a

Please sign in to comment.