Skip to content

Commit 1e0c950

Browse files
committed
Implement Debug for Res and ResMut (#2050)
This commit adds blanket implementations of Debug for Res and ResMut, as discussed in #2048.
1 parent c9b33e1 commit 1e0c950

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

crates/bevy_ecs/src/system/system_param.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::{
1010
pub use bevy_ecs_macros::SystemParam;
1111
use bevy_ecs_macros::{all_tuples, impl_query_set};
1212
use std::{
13+
fmt::Debug,
1314
marker::PhantomData,
1415
ops::{Deref, DerefMut},
1516
};
@@ -174,6 +175,15 @@ pub struct Res<'w, T: Component> {
174175
change_tick: u32,
175176
}
176177

178+
impl<'w, T: Component> Debug for Res<'w, T>
179+
where
180+
T: Debug,
181+
{
182+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
183+
f.debug_tuple("Res").field(&self.value).finish()
184+
}
185+
}
186+
177187
impl<'w, T: Component> Res<'w, T> {
178188
/// Returns true if (and only if) this resource been added since the last execution of this
179189
/// system.
@@ -318,6 +328,15 @@ pub struct ResMut<'w, T: Component> {
318328
change_tick: u32,
319329
}
320330

331+
impl<'w, T: Component> Debug for ResMut<'w, T>
332+
where
333+
T: Debug,
334+
{
335+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
336+
f.debug_tuple("ResMut").field(&self.value).finish()
337+
}
338+
}
339+
321340
impl<'w, T: Component> ResMut<'w, T> {
322341
/// Returns true if (and only if) this resource been added since the last execution of this
323342
/// system.
@@ -520,6 +539,15 @@ impl<'a> SystemParamFetch<'a> for CommandQueue {
520539
/// ```
521540
pub struct Local<'a, T: Component>(&'a mut T);
522541

542+
impl<'a, T: Component> Debug for Local<'a, T>
543+
where
544+
T: Debug,
545+
{
546+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
547+
f.debug_tuple("Local").field(&self.0).finish()
548+
}
549+
}
550+
523551
impl<'a, T: Component> Deref for Local<'a, T> {
524552
type Target = T;
525553

@@ -661,6 +689,15 @@ pub struct NonSend<'w, T> {
661689
change_tick: u32,
662690
}
663691

692+
impl<'w, T> Debug for NonSend<'w, T>
693+
where
694+
T: Debug,
695+
{
696+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
697+
f.debug_tuple("NonSend").field(&self.value).finish()
698+
}
699+
}
700+
664701
impl<'w, T: Component> NonSend<'w, T> {
665702
/// Returns true if (and only if) this resource been added since the last execution of this
666703
/// system.
@@ -807,7 +844,7 @@ impl<'a, T: 'static> DerefMut for NonSendMut<'a, T> {
807844

808845
impl<'a, T: 'static + core::fmt::Debug> core::fmt::Debug for NonSendMut<'a, T> {
809846
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
810-
self.value.fmt(f)
847+
f.debug_tuple("NonSendMut").field(&self.value).finish()
811848
}
812849
}
813850

0 commit comments

Comments
 (0)