From af091c5bf82b7edce0d1ad846011ffa5dea63189 Mon Sep 17 00:00:00 2001 From: niedzwiedzw Date: Wed, 12 Jul 2023 16:20:19 +0200 Subject: [PATCH] turns out Result combinators are not marked with #[trace_caller], so it must be written without function nesting in order to work --- packages/hooks/src/use_shared_state.rs | 50 +++++++++++++------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/packages/hooks/src/use_shared_state.rs b/packages/hooks/src/use_shared_state.rs index cc1679b09..5ab88b7bd 100644 --- a/packages/hooks/src/use_shared_state.rs +++ b/packages/hooks/src/use_shared_state.rs @@ -263,19 +263,19 @@ impl UseSharedState { #[cfg_attr(debug_assertions, track_caller)] #[cfg_attr(debug_assertions, inline(never))] pub fn try_read(&self) -> UseSharedStateResult> { - self.inner - .try_borrow() - .map_err(|source| UseSharedStateError::AlreadyBorrowedMutably { + match self.inner.try_borrow() { + Ok(value) => { + self.debug_track_borrow(); + Ok(Ref::map(value, |inner| &inner.value)) + } + Err(source) => Err(UseSharedStateError::AlreadyBorrowedMutably { source, type_name: std::any::type_name::(), location: debug_location!(), #[cfg(debug_assertions)] previous_borrow: *self.previous_borrow.borrow(), - }) - .map(|value| { - self.debug_track_borrow(); - Ref::map(value, |inner| &inner.value) - }) + }), + } } /// Read the shared value @@ -295,20 +295,20 @@ impl UseSharedState { #[cfg_attr(debug_assertions, track_caller)] #[cfg_attr(debug_assertions, inline(never))] pub fn try_write(&self) -> UseSharedStateResult> { - self.inner - .try_borrow_mut() - .map_err(|source| UseSharedStateError::AlreadyBorrowed { + match self.inner.try_borrow_mut() { + Ok(mut value) => { + self.debug_track_borrow_mut(); + value.notify_consumers(); + Ok(RefMut::map(value, |inner| &mut inner.value)) + } + Err(source) => Err(UseSharedStateError::AlreadyBorrowed { source, type_name: std::any::type_name::(), location: crate::debug_location!(), #[cfg(debug_assertions)] previous_borrow: *self.previous_borrow.borrow(), - }) - .map(|mut value| { - value.notify_consumers(); - self.debug_track_borrow_mut(); - RefMut::map(value, |inner| &mut inner.value) - }) + }), + } } /// Calling "write" will force the component to re-render @@ -331,19 +331,19 @@ impl UseSharedState { #[cfg_attr(debug_assertions, track_caller)] #[cfg_attr(debug_assertions, inline(never))] pub fn try_write_silent(&self) -> UseSharedStateResult> { - self.inner - .try_borrow_mut() - .map_err(|source| UseSharedStateError::AlreadyBorrowed { + match self.inner.try_borrow_mut() { + Ok(value) => { + self.debug_track_borrow_mut(); + Ok(RefMut::map(value, |inner| &mut inner.value)) + } + Err(source) => Err(UseSharedStateError::AlreadyBorrowed { source, type_name: std::any::type_name::(), location: crate::debug_location!(), #[cfg(debug_assertions)] previous_borrow: *self.previous_borrow.borrow(), - }) - .map(|value| { - self.debug_track_borrow_mut(); - RefMut::map(value, |inner| &mut inner.value) - }) + }), + } } /// Writes the value without forcing a re-render