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

Add Debug to all structs to implement it for Pattern #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

wspeirs
Copy link

@wspeirs wspeirs commented Sep 5, 2023

Title says it all... just adding #[derive(Debug)] to all the structs required to implement Debug for Pattern.

@cassaundra
Copy link
Owner

Thanks for the PR. I can see where having Pattern implement Debug would be useful. Because we're using Yoke, #[derive(Debug)]'s output reveals some internals of the library that I think might just confuse users. For example:

Pattern { inner: Yoke { yokeable: PatternInner { elements: [Substring("a"), Wildcard(Wildcard { minimum: 0, is_many: true }), Substring("b")] }, cart: "a*b" } }

What would you think about having a simpler debug output, maybe even just the original string? (e.g. "a*b") See the fmt docs for examples of how to write custom derives. I believe you can get the original pattern string out just with Yoke::backing_cart, if that helps.

@hoijui
Copy link

hoijui commented Dec 18, 2023

What would you think about having a simpler debug output, maybe even just the original string? (e.g. "a*b") See the fmt docs for examples of how to write custom derives. I believe you can get the original pattern string out just with Yoke::backing_cart, if that helps.

At first, I though that makes sense, but then I became unsure ...
There is Debug and there is Display; which should be used how and when?

Researching a bit, I found this in the docs:

These two formatting traits have distinct purposes:

  • fmt::Display implementations assert that the type can be faithfully represented as a UTF-8 string at all times. It is not expected that all types implement the Display trait.
  • fmt::Debug implementations should be implemented for all public types. Output will typically represent the internal state as faithfully as possible. The purpose of the Debug trait is to facilitate debugging Rust code. In most cases, using #[derive(Debug)] is sufficient and recommended.

So I think it is more correct to do it as this PR does for Debug, and do it the way you suggest @cassaundra (e.g. "a*b") for Display.

@hoijui
Copy link

hoijui commented Dec 18, 2023

... It would be nice to have that Display impl too!

Edit: @wspeirs Did it in PR #12 !

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.

3 participants