Skip to content
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

Make impl Debug for Rwlock simpler #423

Merged
merged 1 commit into from Dec 5, 2023
Merged

Conversation

ldm0
Copy link
Contributor

@ldm0 ldm0 commented Dec 4, 2023

simple improvement

}
}
Some(guard) => d.field("data", &&*guard),
None => d.field("data", &format_args!("<locked>")),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format_args! is not needed here. field accepts any &dyn Debug which includes str.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without format_args!, the <locked> will be wrapped with quotes, e.g.: Rwlock { data: "<locked>" }

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment that explains this? It is not obvious from looking at the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment added

.finish()
}
}
Some(guard) => d.field("data", &&*guard),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the &&* really needed here? Can this just be &*?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

T is ?Sized, which means &T cannot be coerced to &dyn Debug. That's why there is an additional &
image

@Amanieu Amanieu merged commit adbad82 into Amanieu:master Dec 5, 2023
37 checks passed
@Amanieu
Copy link
Owner

Amanieu commented Dec 5, 2023

Thanks!

@ldm0 ldm0 deleted the simple_debug branch December 5, 2023 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants