fix some clippy lints in dioxus signals

This commit is contained in:
Evan Almloff committed 2024-01-16 16:31:07 -06:00
1 parent ecf17b351c
commit 397015df31
2 files changed
+12 -6

No files matched your search

+3 -3
View File
@@ -54,7 +54,7 @@ pub(crate) fn get_effect_ref() -> EffectStackRef {
while let Some(id) = receiver.next().await { while let Some(id) = receiver.next().await {
EFFECT_STACK.with(|stack| { EFFECT_STACK.with(|stack| {
let effect_mapping = stack.effect_mapping.read(); let effect_mapping = stack.effect_mapping.read();
if let Some(effect) = effect_mapping.get(&id) { if let Some(mut effect) = effect_mapping.get(&id).copied() {
tracing::trace!("Rerunning effect: {:?}", id); tracing::trace!("Rerunning effect: {:?}", id);
effect.try_run(); effect.try_run();
} else { } else {
@@ -126,7 +126,7 @@ impl Effect {
/// ///
/// The signal will be owned by the current component and will be dropped when the component is dropped. /// The signal will be owned by the current component and will be dropped when the component is dropped.
pub fn new(callback: impl FnMut() + 'static) -> Self { pub fn new(callback: impl FnMut() + 'static) -> Self {
let myself = Self { let mut myself = Self {
source: current_scope_id().expect("in a virtual dom"), source: current_scope_id().expect("in a virtual dom"),
inner: EffectInner::new(Box::new(callback)), inner: EffectInner::new(Box::new(callback)),
}; };
@@ -145,7 +145,7 @@ impl Effect {
} }
/// Run the effect callback immediately. Returns `true` if the effect was run. Returns `false` is the effect is dead. /// Run the effect callback immediately. Returns `true` if the effect was run. Returns `false` is the effect is dead.
pub fn try_run(&self) { pub fn try_run(&mut self) {
tracing::trace!("Running effect: {:?}", self); tracing::trace!("Running effect: {:?}", self);
if let Ok(mut inner) = self.inner.try_write() { if let Ok(mut inner) = self.inner.try_write() {
{ {
+9 -3
View File
@@ -142,7 +142,6 @@ impl<T: 'static, S: Storage<T>> CopyValue<T, S> {
/// Try to read the value. If the value has been dropped, this will return None. /// Try to read the value. If the value has been dropped, this will return None.
#[track_caller] #[track_caller]
pub fn try_read(&self) -> Result<S::Ref, generational_box::BorrowError> { pub fn try_read(&self) -> Result<S::Ref, generational_box::BorrowError> {
self.value.try_read() self.value.try_read()
} }
@@ -155,10 +154,14 @@ impl<T: 'static, S: Storage<T>> CopyValue<T, S> {
/// Try to write the value. If the value has been dropped, this will return None. /// Try to write the value. If the value has been dropped, this will return None.
#[track_caller] #[track_caller]
pub fn try_write(&self) -> Result<S::Mut, generational_box::BorrowMutError> { pub fn try_write(&mut self) -> Result<S::Mut, generational_box::BorrowMutError> {
self.value.try_write() self.value.try_write()
} }
/// Write the value without any lifetime hints. If the value has been dropped, this will panic.
///
/// Note: This is completely safe because the value is stored in a generational box. The lifetime that normally is passed to the returned reference is only used as a hint to user to prevent runtime overlapping borrow panics.
#[track_caller]
pub fn write_unchecked(&self) -> S::Mut { pub fn write_unchecked(&self) -> S::Mut {
self.value.write() self.value.write()
} }
@@ -170,17 +173,20 @@ impl<T: 'static, S: Storage<T>> CopyValue<T, S> {
} }
/// Set the value. If the value has been dropped, this will panic. /// Set the value. If the value has been dropped, this will panic.
#[track_caller]
pub fn set(&self, value: T) { pub fn set(&self, value: T) {
self.value.set(value); self.value.set(value);
} }
/// Run a function with a reference to the value. If the value has been dropped, this will panic. /// Run a function with a reference to the value. If the value has been dropped, this will panic.
#[track_caller]
pub fn with<O>(&self, f: impl FnOnce(&T) -> O) -> O { pub fn with<O>(&self, f: impl FnOnce(&T) -> O) -> O {
let write = self.read(); let write = self.read();
f(&*write) f(&*write)
} }
/// Run a function with a mutable reference to the value. If the value has been dropped, this will panic. /// Run a function with a mutable reference to the value. If the value has been dropped, this will panic.
#[track_caller]
pub fn with_mut<O>(&self, f: impl FnOnce(&mut T) -> O) -> O { pub fn with_mut<O>(&self, f: impl FnOnce(&mut T) -> O) -> O {
let mut write = self.write(); let mut write = self.write();
f(&mut *write) f(&mut *write)
@@ -214,7 +220,7 @@ impl<T: Copy, S: Storage<T>> Deref for CopyValue<T, S> {
// First we create a closure that captures something with the Same in memory layout as Self (MaybeUninit<Self>). // First we create a closure that captures something with the Same in memory layout as Self (MaybeUninit<Self>).
let uninit_callable = MaybeUninit::<Self>::uninit(); let uninit_callable = MaybeUninit::<Self>::uninit();
// Then move that value into the closure. We assume that the closure now has a in memory layout of Self. // Then move that value into the closure. We assume that the closure now has a in memory layout of Self.
let uninit_closure = move || Self::read(unsafe { &*uninit_callable.as_ptr() }).clone(); let uninit_closure = move || *Self::read(unsafe { &*uninit_callable.as_ptr() });
// Check that the size of the closure is the same as the size of Self in case the compiler changed the layout of the closure. // Check that the size of the closure is the same as the size of Self in case the compiler changed the layout of the closure.
let size_of_closure = std::mem::size_of_val(&uninit_closure); let size_of_closure = std::mem::size_of_val(&uninit_closure);