* Fix #2612: adjust readable trait to allow try_peek Our implementation for Readable was inconsistent. We had a try_unchecked variant for read but not for peek. This resolves that by making a breaking change to the Readable interface. * fix doctests too
This commit is contained in:
1 parent
443b9a4af6
commit
e42b71b1ba
13 files changed
+102
-58
No files matched your search
@@ -2,7 +2,7 @@ use crate::{default_impl, fmt_impls, write_impls};
|
||||
use crate::{read::*, write::*, CopyValue, GlobalMemo, GlobalSignal, ReadableRef};
|
||||
use crate::{Memo, WritableRef};
|
||||
use dioxus_core::prelude::*;
|
||||
use generational_box::{AnyStorage, Storage, SyncStorage, UnsyncStorage};
|
||||
use generational_box::{AnyStorage, BorrowResult, Storage, SyncStorage, UnsyncStorage};
|
||||
use std::sync::Arc;
|
||||
use std::{
|
||||
any::Any,
|
||||
@@ -349,9 +349,7 @@ impl<T, S: Storage<SignalData<T>>> Readable for Signal<T, S> {
|
||||
type Storage = S;
|
||||
|
||||
#[track_caller]
|
||||
fn try_read_unchecked(
|
||||
&self,
|
||||
) -> Result<ReadableRef<'static, Self>, generational_box::BorrowError> {
|
||||
fn try_read_unchecked(&self) -> BorrowResult<ReadableRef<'static, Self>> {
|
||||
let inner = self.inner.try_read_unchecked()?;
|
||||
|
||||
if let Some(reactive_context) = ReactiveContext::current() {
|
||||
@@ -366,9 +364,10 @@ impl<T, S: Storage<SignalData<T>>> Readable for Signal<T, S> {
|
||||
///
|
||||
/// If the signal has been dropped, this will panic.
|
||||
#[track_caller]
|
||||
fn peek_unchecked(&self) -> ReadableRef<'static, Self> {
|
||||
let inner = self.inner.try_read_unchecked().unwrap();
|
||||
S::map(inner, |v| &v.value)
|
||||
fn try_peek_unchecked(&self) -> BorrowResult<ReadableRef<'static, Self>> {
|
||||
self.inner
|
||||
.try_read_unchecked()
|
||||
.map(|inner| S::map(inner, |v| &v.value))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user