Skip to content

[Merged by Bors] - Implement Debug for Res and ResMut #2050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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