fix signal error message and add tests (#2118)

This commit is contained in:
Evan Almloff authored and GitHub committed 2024-03-20 08:45:27 -07:00
1 parent 58f7efafea
commit 9f283f571f
10 files changed
+187 -121

No files matched your search

+2
View File
@@ -121,12 +121,14 @@ impl<T: 'static, S: Storage<T>> Readable for CopyValue<T, S> {
type Target = T;
type Storage = S;
#[track_caller]
fn try_read_unchecked(
&self,
) -> Result<ReadableRef<'static, Self>, generational_box::BorrowError> {
self.value.try_read()
}
#[track_caller]
fn peek_unchecked(&self) -> ReadableRef<'static, Self> {
self.value.read()
}
+1
View File
@@ -67,6 +67,7 @@ pub trait Readable {
/// Get a reference to the value without checking the lifetime. This will subscribe the current scope to the signal.
///
/// NOTE: This method is completely safe because borrow checking is done at runtime.
#[track_caller]
fn read_unchecked(&self) -> ReadableRef<'static, Self> {
self.try_read_unchecked().unwrap()
}
+3
View File
@@ -52,6 +52,7 @@ pub trait Writable: Readable {
/// Get a mutable reference to the value without checking the lifetime. This will update any subscribers.
///
/// NOTE: This method is completely safe because borrow checking is done at runtime.
#[track_caller]
fn write_unchecked(&self) -> WritableRef<'static, Self> {
self.try_write_unchecked().unwrap()
}
@@ -114,11 +115,13 @@ pub trait Writable: Readable {
/// An extension trait for Writable<Option<T>> that provides some convenience methods.
pub trait WritableOptionExt<T: 'static>: Writable<Target = Option<T>> {
/// Gets the value out of the Option, or inserts the given value if the Option is empty.
#[track_caller]
fn get_or_insert(&mut self, default: T) -> WritableRef<'_, Self, T> {
self.get_or_insert_with(|| default)
}
/// Gets the value out of the Option, or inserts the value returned by the given function if the Option is empty.
#[track_caller]
fn get_or_insert_with(&mut self, default: impl FnOnce() -> T) -> WritableRef<'_, Self, T> {
let is_none = self.read().is_none();
if is_none {