Skip to content

Adding examples for deriving Debug and Display. #424

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
wants to merge 2 commits into from

Conversation

plauche
Copy link

@plauche plauche commented Jul 6, 2018

fixes #402

@AndyGauge
Copy link
Collaborator

I really like the custom enum option. A recent addition to the Rust Cookbook is a spell checker, which can be a pain to use with all the variable names, types, etc. The CI failures need words added to the dictionary to pass. Unfortunately, I haven't merged the changes to Contributing file that supports this. Here's that file: https://github.com/AndyGauge/rust-cookbook/blob/reorganize/CONTRIBUTING.md#linters

@budziq
Copy link
Collaborator

budziq commented Jul 10, 2018

Thanks for contributing @plauche !

I'm not sure that we really need two separate recipes for procedures that are essentially identical (implementation of Debug and Display traits). how about we just limit the example to one of the traits with mention of the other in the textual description? I'd also suggest to mention that this is an alternative to just using #[derive(Debug)]which gives implementer control of the output.

What are your thoughts @AndyGauge ?

@AndyGauge
Copy link
Collaborator

I agree with what @budziq said about there being a single recipe. What I had originally thought of was a #[derive(Debug)] and a Display implementation in a single recipe, with textual description that explains the difference.

@AndyGauge
Copy link
Collaborator

I've made this harder for you, if you need help let me know.

The organization has changed dramatically, so merging master will really mess with the file layout. I'd love for this example to live in Text Processing.

@AndyGauge
Copy link
Collaborator

@plauche Do you want me to make the changes requested?

"Image {{ format: {}, width: {}, height: {} }}",
format, width, height
),
FileType::Text { format } => write!(f, "Text {{ format: {} }}", format),
Copy link

Choose a reason for hiding this comment

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

We actually don't need to manually write out the Text { format: value } struct-like format here. There are methods on the fmt::Formatter like debug_struct that will do this for us and keep it consistent with what you get from #[derive(Debug)].

@AndyGauge AndyGauge closed this Sep 19, 2019
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.

Recipe: Implement Display, Debug for custom type
4 participants