mirror of
https://github.com/Zenithsiz/dynatos.git
synced 2026-02-08 21:09:52 +00:00
SignalGet is now an extension trait.
This commit is contained in:
@@ -148,18 +148,6 @@ impl<T, E> Clone for LazyLoadable<T, E> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, E> SignalGet for LazyLoadable<T, E>
|
||||
where
|
||||
T: Copy,
|
||||
E: Clone,
|
||||
{
|
||||
type Value = Loadable<T, E>;
|
||||
|
||||
fn get(&self) -> Self::Value {
|
||||
self.with(|value| value.clone())
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Use a `Loadable<&T, E>` when `SignalWith` allows?
|
||||
impl<T, E> SignalWith for LazyLoadable<T, E>
|
||||
where
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
// Imports
|
||||
use {
|
||||
crate::{Effect, Signal, SignalGet, SignalSet, SignalWith},
|
||||
crate::{Effect, Signal, SignalSet, SignalWith},
|
||||
std::fmt,
|
||||
};
|
||||
|
||||
@@ -35,17 +35,6 @@ impl<T> Derived<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> SignalGet for Derived<T>
|
||||
where
|
||||
T: Copy,
|
||||
{
|
||||
type Value = T;
|
||||
|
||||
fn get(&self) -> Self::Value {
|
||||
self.with(|value| *value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> SignalWith for Derived<T> {
|
||||
type Value = T;
|
||||
|
||||
|
||||
@@ -20,12 +20,16 @@ pub use self::{
|
||||
};
|
||||
|
||||
/// Signal get
|
||||
pub trait SignalGet {
|
||||
/// Value type
|
||||
type Value;
|
||||
|
||||
#[extend::ext(name = SignalGet)]
|
||||
pub impl<S> 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())
|
||||
}
|
||||
|
||||
@@ -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<T> Signal<T> {
|
||||
|
||||
impl<T: ?Sized, U: ?Sized> CoerceUnsized<Signal<U>> for Signal<T> where T: Unsize<U> {}
|
||||
|
||||
impl<T> SignalGet for Signal<T>
|
||||
where
|
||||
T: Copy,
|
||||
{
|
||||
type Value = T;
|
||||
|
||||
fn get(&self) -> Self::Value {
|
||||
self.with(|value| *value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ?Sized> SignalWith for Signal<T> {
|
||||
type Value = T;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! `Option<T>` Signal with default value
|
||||
|
||||
// Imports
|
||||
use crate::{SignalGet, SignalReplace, SignalSet, SignalUpdate, SignalWith};
|
||||
use crate::{SignalReplace, SignalSet, SignalUpdate, SignalWith};
|
||||
|
||||
/// Wrapper for a `Signal<Option<T>>` with a default value
|
||||
#[derive(Clone)]
|
||||
@@ -20,18 +20,6 @@ impl<S, T> WithDefault<S, T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<S, T> SignalGet for WithDefault<S, T>
|
||||
where
|
||||
S: SignalGet<Value = Option<T>>,
|
||||
T: Copy,
|
||||
{
|
||||
type Value = T;
|
||||
|
||||
fn get(&self) -> Self::Value {
|
||||
self.inner.get().unwrap_or(self.default)
|
||||
}
|
||||
}
|
||||
|
||||
impl<S, T> SignalWith for WithDefault<S, T>
|
||||
where
|
||||
S: SignalWith<Value = Option<T>>,
|
||||
|
||||
@@ -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<T> QuerySignal<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> SignalGet for QuerySignal<T>
|
||||
where
|
||||
T: Copy,
|
||||
{
|
||||
type Value = Option<T>;
|
||||
|
||||
fn get(&self) -> Self::Value {
|
||||
self.with(|value| *value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> SignalWith for QuerySignal<T> {
|
||||
type Value = Option<T>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user