mirror of
https://github.com/Zenithsiz/dynatos.git
synced 2026-02-08 21:09:52 +00:00
SignalUpdate now uses GATs for it's Value type.
This commit is contained in:
@@ -130,7 +130,8 @@ impl<T, E> LazyLoadable<T, E> {
|
||||
/// Will notify any subscribers of the value.
|
||||
pub fn update_unloaded<R>(&self, f: impl FnOnce(Loadable<&mut T, E>) -> R) -> R
|
||||
where
|
||||
E: Clone,
|
||||
T: 'static,
|
||||
E: Clone + 'static,
|
||||
{
|
||||
let mut output = None;
|
||||
self.inner.update(|inner| output = Some(f(inner.as_mut())));
|
||||
@@ -168,15 +169,16 @@ where
|
||||
|
||||
impl<T, E> SignalUpdate for LazyLoadable<T, E>
|
||||
where
|
||||
E: Clone,
|
||||
T: 'static,
|
||||
E: Clone + 'static,
|
||||
{
|
||||
type Value = Loadable<T, E>;
|
||||
type Value<'a> = Loadable<&'a mut T, E>;
|
||||
|
||||
fn update<F, O>(&self, f: F) -> O
|
||||
where
|
||||
F: FnOnce(&mut Self::Value) -> O,
|
||||
F: for<'a> FnOnce(Self::Value<'a>) -> O,
|
||||
{
|
||||
self.load();
|
||||
self.inner.update(f)
|
||||
self.inner.update(|loadable| f(loadable.as_mut()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,6 +102,7 @@ struct EffectFn<T, F: ?Sized> {
|
||||
|
||||
impl<T, F> FnOnce<()> for EffectFn<T, F>
|
||||
where
|
||||
T: 'static,
|
||||
F: Fn() -> T,
|
||||
{
|
||||
type Output = ();
|
||||
@@ -112,6 +113,7 @@ where
|
||||
}
|
||||
impl<T, F> FnMut<()> for EffectFn<T, F>
|
||||
where
|
||||
T: 'static,
|
||||
F: Fn() -> T,
|
||||
{
|
||||
extern "rust-call" fn call_mut(&mut self, args: ()) -> Self::Output {
|
||||
@@ -120,6 +122,7 @@ where
|
||||
}
|
||||
impl<T, F> Fn<()> for EffectFn<T, F>
|
||||
where
|
||||
T: 'static,
|
||||
F: Fn() -> T,
|
||||
{
|
||||
extern "rust-call" fn call(&self, _args: ()) -> Self::Output {
|
||||
|
||||
@@ -99,16 +99,16 @@ pub trait SignalWith {
|
||||
|
||||
/// Types which may be set by [`SignalSet`]
|
||||
pub trait SignalSetWith<T>: Sized {
|
||||
fn set(&mut self, new_value: T);
|
||||
fn set(self, new_value: T);
|
||||
}
|
||||
|
||||
impl<T> SignalSetWith<T> for T {
|
||||
fn set(&mut self, new_value: T) {
|
||||
impl<T> SignalSetWith<T> for &'_ mut T {
|
||||
fn set(self, new_value: T) {
|
||||
*self = new_value;
|
||||
}
|
||||
}
|
||||
impl<T> SignalSetWith<T> for Option<T> {
|
||||
fn set(&mut self, new_value: T) {
|
||||
impl<T> SignalSetWith<T> for &'_ mut Option<T> {
|
||||
fn set(self, new_value: T) {
|
||||
*self = Some(new_value);
|
||||
}
|
||||
}
|
||||
@@ -122,7 +122,7 @@ pub trait SignalSet<Value> {
|
||||
impl<S, T> SignalSet<T> for S
|
||||
where
|
||||
S: SignalUpdate,
|
||||
S::Value: SignalSetWith<T>,
|
||||
for<'a> S::Value<'a>: SignalSetWith<T>,
|
||||
{
|
||||
fn set(&self, new_value: T) {
|
||||
self.update(|value| SignalSetWith::set(value, new_value));
|
||||
@@ -138,12 +138,12 @@ pub trait SignalReplace<Value> {
|
||||
/// Signal update
|
||||
pub trait SignalUpdate {
|
||||
/// Value type
|
||||
type Value: ?Sized;
|
||||
type Value<'a>: ?Sized;
|
||||
|
||||
/// Updates the signal value
|
||||
fn update<F, O>(&self, f: F) -> O
|
||||
where
|
||||
F: FnOnce(&mut Self::Value) -> O;
|
||||
F: for<'a> FnOnce(Self::Value<'a>) -> O;
|
||||
}
|
||||
|
||||
/// Types that may be converted into a subscriber
|
||||
|
||||
@@ -63,18 +63,18 @@ impl<T: ?Sized + 'static> SignalWith for Signal<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> SignalReplace<T> for Signal<T> {
|
||||
impl<T: 'static> SignalReplace<T> for Signal<T> {
|
||||
fn replace(&self, new_value: T) -> T {
|
||||
self.update(|value| mem::replace(value, new_value))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ?Sized> SignalUpdate for Signal<T> {
|
||||
type Value = T;
|
||||
impl<T: ?Sized + 'static> SignalUpdate for Signal<T> {
|
||||
type Value<'a> = &'a mut T;
|
||||
|
||||
fn update<F, O>(&self, f: F) -> O
|
||||
where
|
||||
F: FnOnce(&mut Self::Value) -> O,
|
||||
F: for<'a> FnOnce(Self::Value<'a>) -> O,
|
||||
{
|
||||
// Update the value and get the output
|
||||
let output = {
|
||||
|
||||
@@ -59,14 +59,14 @@ where
|
||||
|
||||
impl<S, T> SignalUpdate for WithDefault<S, T>
|
||||
where
|
||||
S: SignalUpdate<Value = Option<T>>,
|
||||
T: Copy,
|
||||
S: for<'a> SignalUpdate<Value<'a> = &'a mut Option<T>>,
|
||||
T: Copy + 'static,
|
||||
{
|
||||
type Value = T;
|
||||
type Value<'a> = &'a mut T;
|
||||
|
||||
fn update<F, O>(&self, f: F) -> O
|
||||
where
|
||||
F: FnOnce(&mut Self::Value) -> O,
|
||||
F: for<'a> FnOnce(Self::Value<'a>) -> O,
|
||||
{
|
||||
self.inner.update(|value| f(value.get_or_insert(self.default)))
|
||||
}
|
||||
|
||||
@@ -55,11 +55,11 @@ impl SignalWith for Location {
|
||||
}
|
||||
|
||||
impl SignalUpdate for Location {
|
||||
type Value = Url;
|
||||
type Value<'a> = &'a mut Url;
|
||||
|
||||
fn update<F, O>(&self, f: F) -> O
|
||||
where
|
||||
F: FnOnce(&mut Self::Value) -> O,
|
||||
F: for<'a> FnOnce(Self::Value<'a>) -> O,
|
||||
{
|
||||
self.0.update(|inner| {
|
||||
let output = f(&mut inner.location);
|
||||
|
||||
@@ -87,11 +87,11 @@ impl<T> SignalUpdate for QueryArraySignal<T>
|
||||
where
|
||||
T: ToString + 'static,
|
||||
{
|
||||
type Value = Vec<T>;
|
||||
type Value<'a> = &'a mut Vec<T>;
|
||||
|
||||
fn update<F, O>(&self, f: F) -> O
|
||||
where
|
||||
F: FnOnce(&mut Self::Value) -> O,
|
||||
F: for<'a> FnOnce(Self::Value<'a>) -> O,
|
||||
{
|
||||
// Update the value
|
||||
let output = self.inner.update(f);
|
||||
|
||||
@@ -86,11 +86,11 @@ impl<T> SignalUpdate for QuerySignal<T>
|
||||
where
|
||||
T: ToString + 'static,
|
||||
{
|
||||
type Value = Option<T>;
|
||||
type Value<'a> = &'a mut Option<T>;
|
||||
|
||||
fn update<F, O>(&self, f: F) -> O
|
||||
where
|
||||
F: FnOnce(&mut Self::Value) -> O,
|
||||
F: for<'a> FnOnce(Self::Value<'a>) -> O,
|
||||
{
|
||||
// Update the value
|
||||
let output = self.inner.update(f);
|
||||
|
||||
Reference in New Issue
Block a user