Skip to content

Commit

Permalink
Implement Debug for Res and ResMut (bevyengine#2050)
Browse files Browse the repository at this point in the history
This commit adds blanket implementations of Debug for Res and ResMut, as discussed in bevyengine#2048.
  • Loading branch information
forbjok authored and ostwilkens committed Jul 27, 2021
1 parent ba78fbb commit 43a09ca
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion crates/bevy_ecs/src/system/system_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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()
}
}

Expand Down

0 comments on commit 43a09ca

Please sign in to comment.