feat(signals): add WritableResultExt trait (#5338)
* feat(signals): add WritableResultExt trait Add WritableResultExt mirroring the existing ReadableResultExt, providing mutable access to signal values holding Result<T, E>. Methods: - as_mut(): returns Result<WritableRef<T>, WritableRef<E>> - unwrap_mut(): returns WritableRef<T>, panics if Err Closes #5293 * refactor(signals): use descriptive expect messages in WritableResultExt::as_mut Replace bare .unwrap() calls with .expect() containing a descriptive message about the failure mode. This gives better diagnostics if the Result variant changes between the read and write lock acquisitions. * switch to a single write to avoid race conditions with sync signals --------- Co-authored-by: Evan Almloff <evanalmloff@gmail.com>
This commit is contained in:
1 parent
d312ef84d2
commit
b7958d3d17
2 files changed
+51
-3
No files matched your search
@@ -419,9 +419,19 @@ pub trait ReadableResultExt<T, E>: Readable<Target = Result<T, E>> {
|
||||
T: 'static,
|
||||
E: 'static,
|
||||
{
|
||||
<Self::Storage as AnyStorage>::try_map(self.read(), |v| v.as_ref().ok()).ok_or(
|
||||
<Self::Storage as AnyStorage>::map(self.read(), |v| v.as_ref().err().unwrap()),
|
||||
)
|
||||
let read = self.read();
|
||||
match read.deref() {
|
||||
Ok(_) => Ok(<Self::Storage as AnyStorage>::map(read, |v| {
|
||||
v.as_ref()
|
||||
.ok()
|
||||
.expect("Result variant changed between read and map")
|
||||
})),
|
||||
Err(_) => Err(<Self::Storage as AnyStorage>::map(read, |v| {
|
||||
v.as_ref()
|
||||
.err()
|
||||
.expect("Result variant changed between read and map")
|
||||
})),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user