From 1e0c950004a0c89e5b7704d6f77fecb083ee3ef1 Mon Sep 17 00:00:00 2001 From: forbjok Date: Sat, 1 May 2021 02:32:32 +0000 Subject: [PATCH] Implement Debug for Res and ResMut (#2050) This commit adds blanket implementations of Debug for Res and ResMut, as discussed in https://github.com/bevyengine/bevy/issues/2048. --- crates/bevy_ecs/src/system/system_param.rs | 39 +++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/crates/bevy_ecs/src/system/system_param.rs b/crates/bevy_ecs/src/system/system_param.rs index 511fc31927d9e..5dce8e4b2e477 100644 --- a/crates/bevy_ecs/src/system/system_param.rs +++ b/crates/bevy_ecs/src/system/system_param.rs @@ -10,6 +10,7 @@ use crate::{ pub use bevy_ecs_macros::SystemParam; use bevy_ecs_macros::{all_tuples, impl_query_set}; use std::{ + fmt::Debug, marker::PhantomData, ops::{Deref, DerefMut}, }; @@ -174,6 +175,15 @@ pub struct Res<'w, T: Component> { change_tick: u32, } +impl<'w, T: Component> Debug for Res<'w, T> +where + T: Debug, +{ + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_tuple("Res").field(&self.value).finish() + } +} + impl<'w, T: Component> Res<'w, T> { /// Returns true if (and only if) this resource been added since the last execution of this /// system. @@ -318,6 +328,15 @@ pub struct ResMut<'w, T: Component> { change_tick: u32, } +impl<'w, T: Component> Debug for ResMut<'w, T> +where + T: Debug, +{ + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_tuple("ResMut").field(&self.value).finish() + } +} + impl<'w, T: Component> ResMut<'w, T> { /// Returns true if (and only if) this resource been added since the last execution of this /// system. @@ -520,6 +539,15 @@ impl<'a> SystemParamFetch<'a> for CommandQueue { /// ``` pub struct Local<'a, T: Component>(&'a mut T); +impl<'a, T: Component> Debug for Local<'a, T> +where + T: Debug, +{ + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_tuple("Local").field(&self.0).finish() + } +} + impl<'a, T: Component> Deref for Local<'a, T> { type Target = T; @@ -661,6 +689,15 @@ pub struct NonSend<'w, T> { change_tick: u32, } +impl<'w, T> Debug for NonSend<'w, T> +where + T: Debug, +{ + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_tuple("NonSend").field(&self.value).finish() + } +} + impl<'w, T: Component> NonSend<'w, T> { /// Returns true if (and only if) this resource been added since the last execution of this /// system. @@ -807,7 +844,7 @@ impl<'a, T: 'static> DerefMut for NonSendMut<'a, T> { impl<'a, T: 'static + core::fmt::Debug> core::fmt::Debug for NonSendMut<'a, T> { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - self.value.fmt(f) + f.debug_tuple("NonSendMut").field(&self.value).finish() } }