From cc7f861637d069e82ad1e13ee525b9186108f7cd Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Mon, 16 Sep 2024 21:58:23 -0400 Subject: [PATCH] fix: add missing Debug and DefinedAt impls for Resource/ArcResource (closes #2983) (#2984) --- leptos_server/src/resource.rs | 64 ++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/leptos_server/src/resource.rs b/leptos_server/src/resource.rs index af9aa12c8..30b7b437a 100644 --- a/leptos_server/src/resource.rs +++ b/leptos_server/src/resource.rs @@ -24,12 +24,37 @@ use reactive_graph::{ prelude::*, signal::{ArcRwSignal, RwSignal}, }; -use std::{future::IntoFuture, ops::Deref}; +use std::{future::IntoFuture, ops::Deref, panic::Location}; pub struct ArcResource { ser: PhantomData, refetch: ArcRwSignal, data: ArcAsyncDerived, + #[cfg(debug_assertions)] + defined_at: &'static Location<'static>, +} + +impl Debug for ArcResource { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let mut d = f.debug_struct("ArcResource"); + d.field("ser", &self.ser).field("data", &self.data); + #[cfg(debug_assertions)] + d.field("defined_at", self.defined_at); + d.finish_non_exhaustive() + } +} + +impl DefinedAt for ArcResource { + fn defined_at(&self) -> Option<&'static Location<'static>> { + #[cfg(debug_assertions)] + { + Some(self.defined_at) + } + #[cfg(not(debug_assertions))] + { + None + } + } } impl Clone for ArcResource { @@ -38,6 +63,8 @@ impl Clone for ArcResource { ser: self.ser, refetch: self.refetch.clone(), data: self.data.clone(), + #[cfg(debug_assertions)] + defined_at: self.defined_at, } } } @@ -131,6 +158,8 @@ where ser: PhantomData, data, refetch, + #[cfg(debug_assertions)] + defined_at: Location::caller(), } } @@ -448,6 +477,37 @@ where ser: PhantomData, data: AsyncDerived, refetch: RwSignal, + #[cfg(debug_assertions)] + defined_at: &'static Location<'static>, +} + +impl Debug for Resource +where + T: Send + Sync + 'static, +{ + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let mut d = f.debug_struct("ArcResource"); + d.field("ser", &self.ser).field("data", &self.data); + #[cfg(debug_assertions)] + d.field("defined_at", self.defined_at); + d.finish_non_exhaustive() + } +} + +impl DefinedAt for Resource +where + T: Send + Sync + 'static, +{ + fn defined_at(&self) -> Option<&'static Location<'static>> { + #[cfg(debug_assertions)] + { + Some(self.defined_at) + } + #[cfg(not(debug_assertions))] + { + None + } + } } impl Copy for Resource {} @@ -703,6 +763,8 @@ where ser: PhantomData, data: data.into(), refetch: refetch.into(), + #[cfg(debug_assertions)] + defined_at: Location::caller(), } }