+
Skip to content

Add HideName option to printer #33

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

Merged

Conversation

LeonHuston
Copy link
Contributor

I have run into a situation where we are using assert to compare some structs, however some of these structs have some fields we don't care about but the same type as one of the fields we are directly trying to compare. This means the existing Hide option does not work because it will exclude everything.

This PR adds a slightly alternative option HideName which will hide all struct fields matching that given name, i've kept it at struct names for now but it could be extended to map keys too if we so wished. Included a test similar to the existing ones, but if you want more let me know :)

repr.go Outdated
@@ -105,6 +105,12 @@ func Hide[T any]() Option {
}
}

func HideName(name string) Option {
Copy link
Owner

Choose a reason for hiding this comment

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

I don't mind the idea, but can you rename this to HideField or something similar, as "name" is a bit ambiguous - it could be field name or type name.

Copy link
Owner

Choose a reason for hiding this comment

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

Also can you write a doc comment please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem, ive done this now :)

Copy link
Owner

Choose a reason for hiding this comment

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

Thanks!

Also, NZ represent! :)

@LeonHuston LeonHuston force-pushed the ignore-struct-field-by-name branch from 10e4ceb to 66daa83 Compare June 5, 2025 03:47
@alecthomas alecthomas merged commit 21b2102 into alecthomas:master Jun 5, 2025
2 checks passed
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.

2 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载