diff --git a/dynatos-loadable/src/lazy_loadable.rs b/dynatos-loadable/src/lazy_loadable.rs index e1597c0..6f6cd89 100644 --- a/dynatos-loadable/src/lazy_loadable.rs +++ b/dynatos-loadable/src/lazy_loadable.rs @@ -148,18 +148,6 @@ impl Clone for LazyLoadable { } } -impl SignalGet for LazyLoadable -where - T: Copy, - E: Clone, -{ - type Value = Loadable; - - fn get(&self) -> Self::Value { - self.with(|value| value.clone()) - } -} - // TODO: Use a `Loadable<&T, E>` when `SignalWith` allows? impl SignalWith for LazyLoadable where diff --git a/dynatos-reactive/src/derived.rs b/dynatos-reactive/src/derived.rs index 48e8962..2b52908 100644 --- a/dynatos-reactive/src/derived.rs +++ b/dynatos-reactive/src/derived.rs @@ -5,7 +5,7 @@ // Imports use { - crate::{Effect, Signal, SignalGet, SignalSet, SignalWith}, + crate::{Effect, Signal, SignalSet, SignalWith}, std::fmt, }; @@ -35,17 +35,6 @@ impl Derived { } } -impl SignalGet for Derived -where - T: Copy, -{ - type Value = T; - - fn get(&self) -> Self::Value { - self.with(|value| *value) - } -} - impl SignalWith for Derived { type Value = T; diff --git a/dynatos-reactive/src/lib.rs b/dynatos-reactive/src/lib.rs index 5f04ad2..7673cd9 100644 --- a/dynatos-reactive/src/lib.rs +++ b/dynatos-reactive/src/lib.rs @@ -20,12 +20,16 @@ pub use self::{ }; /// Signal get -pub trait SignalGet { - /// Value type - type Value; - +#[extend::ext(name = SignalGet)] +pub impl S +where + S: SignalWith, + S::Value: Copy, +{ /// Gets the signal value, by copying it - fn get(&self) -> Self::Value; + fn get(&self) -> S::Value { + self.with(|value| *value) + } } /// Signal cloned @@ -35,6 +39,7 @@ where S: SignalWith, S::Value: Clone, { + /// Gets the signal value, by cloning it fn get_cloned(&self) -> S::Value { self.with(|value| value.clone()) } diff --git a/dynatos-reactive/src/signal.rs b/dynatos-reactive/src/signal.rs index 46e848b..119f936 100644 --- a/dynatos-reactive/src/signal.rs +++ b/dynatos-reactive/src/signal.rs @@ -5,7 +5,7 @@ // Imports use { - crate::{Effect, SignalGet, SignalReplace, SignalSet, SignalUpdate, SignalWith, Trigger, WeakEffect}, + crate::{Effect, SignalReplace, SignalSet, SignalUpdate, SignalWith, Trigger, WeakEffect}, std::{cell::RefCell, fmt, marker::Unsize, mem, ops::CoerceUnsized, rc::Rc}, }; @@ -43,17 +43,6 @@ impl Signal { impl CoerceUnsized> for Signal where T: Unsize {} -impl SignalGet for Signal -where - T: Copy, -{ - type Value = T; - - fn get(&self) -> Self::Value { - self.with(|value| *value) - } -} - impl SignalWith for Signal { type Value = T; diff --git a/dynatos-reactive/src/with_default.rs b/dynatos-reactive/src/with_default.rs index be38511..23e844a 100644 --- a/dynatos-reactive/src/with_default.rs +++ b/dynatos-reactive/src/with_default.rs @@ -1,7 +1,7 @@ //! `Option` Signal with default value // Imports -use crate::{SignalGet, SignalReplace, SignalSet, SignalUpdate, SignalWith}; +use crate::{SignalReplace, SignalSet, SignalUpdate, SignalWith}; /// Wrapper for a `Signal>` with a default value #[derive(Clone)] @@ -20,18 +20,6 @@ impl WithDefault { } } -impl SignalGet for WithDefault -where - S: SignalGet>, - T: Copy, -{ - type Value = T; - - fn get(&self) -> Self::Value { - self.inner.get().unwrap_or(self.default) - } -} - impl SignalWith for WithDefault where S: SignalWith>, diff --git a/dynatos-router/src/query_signal.rs b/dynatos-router/src/query_signal.rs index f99635a..98e9470 100644 --- a/dynatos-router/src/query_signal.rs +++ b/dynatos-router/src/query_signal.rs @@ -3,7 +3,7 @@ // Imports use { crate::Location, - dynatos_reactive::{Effect, Signal, SignalGet, SignalReplace, SignalSet, SignalUpdate, SignalWith}, + dynatos_reactive::{Effect, Signal, SignalReplace, SignalSet, SignalUpdate, SignalWith}, std::{collections::HashMap, error::Error as StdError, mem, rc::Rc, str::FromStr}, }; @@ -62,17 +62,6 @@ impl QuerySignal { } } -impl SignalGet for QuerySignal -where - T: Copy, -{ - type Value = Option; - - fn get(&self) -> Self::Value { - self.with(|value| *value) - } -} - impl SignalWith for QuerySignal { type Value = Option;