Fix #2612: adjust readable trait to allow try_peek (#2714)

* 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:
Jonathan Kelley authored and GitHub committed 2024-07-26 18:20:16 -05:00
1 parent 443b9a4af6
commit e42b71b1ba
13 files changed
+102 -58

No files matched your search

+3 -3
View File
@@ -4,7 +4,7 @@ use std::ops::Deref;
use crate::{default_impl, read_impls};
use dioxus_core::{prelude::IntoAttributeValue, ScopeId};
use generational_box::{Storage, UnsyncStorage};
use generational_box::{BorrowResult, Storage, UnsyncStorage};
/// A signal that can only be read from.
pub struct ReadOnlySignal<T: 'static, S: Storage<SignalData<T>> = UnsyncStorage> {
@@ -79,8 +79,8 @@ impl<T, S: Storage<SignalData<T>>> Readable for ReadOnlySignal<T, S> {
///
/// If the signal has been dropped, this will panic.
#[track_caller]
fn peek_unchecked(&self) -> S::Ref<'static, T> {
self.inner.peek_unchecked()
fn try_peek_unchecked(&self) -> BorrowResult<S::Ref<'static, T>> {
self.inner.try_peek_unchecked()
}
}