simplify the readable and writable traits a bit
This commit is contained in:
1 parent
c172914b21
commit
6bc0332052
7 files changed
+20
-49
No files matched your search
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
read::Readable, write::Writable, Effect, EffectInner, GlobalMemo, GlobalSignal, MappedSignal,
|
||||
ReadOnlySignal, ReadableRef, WritableRef,
|
||||
ReadOnlySignal,
|
||||
};
|
||||
use std::{
|
||||
any::Any,
|
||||
@@ -399,7 +399,7 @@ impl<T: 'static, S: Storage<SignalData<T>>> Signal<T, S> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S: Storage<SignalData<T>>> ReadableRef for Signal<T, S> {
|
||||
impl<T, S: Storage<SignalData<T>>> Readable<T> for Signal<T, S> {
|
||||
type Ref<R: ?Sized + 'static> = S::Ref<R>;
|
||||
|
||||
fn map_ref<I, U: ?Sized, F: FnOnce(&I) -> &U>(ref_: Self::Ref<I>, f: F) -> Self::Ref<U> {
|
||||
@@ -412,9 +412,7 @@ impl<T, S: Storage<SignalData<T>>> ReadableRef for Signal<T, S> {
|
||||
) -> Option<Self::Ref<U>> {
|
||||
S::try_map(ref_, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S: Storage<SignalData<T>>> Readable<T> for Signal<T, S> {
|
||||
/// Get the current value of the signal. This will subscribe the current scope to the signal. If you would like to read the signal without subscribing to it, you can use [`Self::peek`] instead.
|
||||
///
|
||||
/// If the signal has been dropped, this will panic.
|
||||
@@ -458,7 +456,7 @@ impl<T, S: Storage<SignalData<T>>> Readable<T> for Signal<T, S> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: 'static, S: Storage<SignalData<T>>> WritableRef for Signal<T, S> {
|
||||
impl<T: 'static, S: Storage<SignalData<T>>> Writable<T> for Signal<T, S> {
|
||||
type Mut<R: ?Sized + 'static> = Write<R, S>;
|
||||
|
||||
fn map_mut<I, U: ?Sized + 'static, F: FnOnce(&mut I) -> &mut U>(
|
||||
@@ -474,9 +472,7 @@ impl<T: 'static, S: Storage<SignalData<T>>> WritableRef for Signal<T, S> {
|
||||
) -> Option<Self::Mut<U>> {
|
||||
Write::filter_map(ref_, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: 'static, S: Storage<SignalData<T>>> Writable<T> for Signal<T, S> {
|
||||
#[track_caller]
|
||||
fn try_write(&self) -> Result<Self::Mut<T>, generational_box::BorrowMutError> {
|
||||
self.inner.try_write().map(|inner| {
|
||||
|
||||
Reference in new issue
Block a user