Skip to content

Commit

Permalink
feat: print inner value in Debug impls
Browse files Browse the repository at this point in the history
  • Loading branch information
Giovanni-Tably committed Feb 29, 2024
1 parent 6a83161 commit ac46521
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
5 changes: 2 additions & 3 deletions leptos_reactive/src/memo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,10 @@ where

impl<T> Copy for Memo<T> {}

impl<T> fmt::Debug for Memo<T> {
impl<T: fmt::Debug> fmt::Debug for Memo<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut s = f.debug_struct("Memo");
s.field("id", &self.id);
s.field("ty", &self.ty);
self.with_untracked(|v| s.field("inner", v));
#[cfg(any(debug_assertions, feature = "ssr"))]
s.field("defined_at", &self.defined_at);
s.finish()
Expand Down
10 changes: 4 additions & 6 deletions leptos_reactive/src/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,11 +772,10 @@ impl<T> Clone for ReadSignal<T> {

impl<T> Copy for ReadSignal<T> {}

impl<T> fmt::Debug for ReadSignal<T> {
impl<T: fmt::Debug> fmt::Debug for ReadSignal<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut s = f.debug_struct("ReadSignal");
s.field("id", &self.id);
s.field("ty", &self.ty);
self.with_untracked(|v| s.field("inner", v));
#[cfg(any(debug_assertions, feature = "ssr"))]
s.field("defined_at", &self.defined_at);
s.finish()
Expand Down Expand Up @@ -1224,11 +1223,10 @@ impl<T> Clone for RwSignal<T> {

impl<T> Copy for RwSignal<T> {}

impl<T> fmt::Debug for RwSignal<T> {
impl<T: fmt::Debug> fmt::Debug for RwSignal<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut s = f.debug_struct("RwSignal");
s.field("id", &self.id);
s.field("ty", &self.ty);
self.with_untracked(|v| s.field("inner", v));
#[cfg(any(debug_assertions, feature = "ssr"))]
s.field("defined_at", &self.defined_at);
s.finish()
Expand Down
14 changes: 7 additions & 7 deletions leptos_reactive/src/signal_wrappers_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl<T> Clone for Signal<T> {

impl<T> Copy for Signal<T> {}

impl<T> core::fmt::Debug for Signal<T> {
impl<T: core::fmt::Debug> core::fmt::Debug for Signal<T> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let mut s = f.debug_struct("Signal");
s.field("inner", &self.inner);
Expand Down Expand Up @@ -458,14 +458,14 @@ impl<T> Clone for SignalTypes<T> {

impl<T> Copy for SignalTypes<T> {}

impl<T> core::fmt::Debug for SignalTypes<T> {
impl<T: core::fmt::Debug> core::fmt::Debug for SignalTypes<T> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::ReadSignal(arg0) => {
f.debug_tuple("ReadSignal").field(arg0).finish()
}
Self::Memo(arg0) => f.debug_tuple("Memo").field(arg0).finish(),
Self::DerivedSignal(_) => f.debug_tuple("DerivedSignal").finish(),
Self::ReadSignal(arg0) => arg0.fmt(f),
Self::Memo(arg0) => arg0.fmt(f),
Self::DerivedSignal(get) => get.with_value(|get| {
f.debug_tuple("DerivedSignal").field(&untrack(get)).finish()
}),
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions leptos_reactive/src/stored_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@ impl<T> Clone for StoredValue<T> {

impl<T> Copy for StoredValue<T> {}

impl<T> fmt::Debug for StoredValue<T> {
impl<T: fmt::Debug> fmt::Debug for StoredValue<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("StoredValue")
.field("id", &self.id)
.field("ty", &self.ty)
.finish()
self.with_value(|v| {
f.debug_struct("StoredValue").field("inner", v).finish()
})
}
}

Expand Down

0 comments on commit ac46521

Please sign in to comment.