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

u/named_type: use fmt to format named type #16745

Merged
merged 2 commits into from
Feb 29, 2024

Conversation

mmaslankaprv
Copy link
Member

@mmaslankaprv mmaslankaprv commented Feb 27, 2024

named_type was previously using a standard stream operator when being printed. This required any type wrapped with named_type to have opertor<< defined instead of relaying on fmt::formatter like a lot of types does. Changed the implementation of named type stream output operator to use fmt library.

Backports Required

  • none - not a bug fix
  • none - this is a backport
  • none - issue does not exist in previous branches
  • none - papercut/not impactful enough to backport
  • v23.3.x
  • v23.2.x
  • v23.1.x

Release Notes

  • none

`named_type` was previously using a standard stream operator when being
printed. This required any type wrapped with `named_type` to have
`opertor<<` defined instead of relaying on `fmt::formatter` like a lot
of types does. Changed the implementation of named type stream output
operator to use `fmt` library.

Signed-off-by: Michal Maslanka <michal@redpanda.com>
@mmaslankaprv mmaslankaprv force-pushed the named-type-formatting branch 3 times, most recently from 00b7165 to 96f1068 Compare February 27, 2024 11:54
Copy link
Member

@travisdowns travisdowns left a comment

Choose a reason for hiding this comment

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

This looks like a good change, but I'm curious why you also changed the output string to no longer include the leading and trailing { }?

@mmaslankaprv
Copy link
Member Author

This looks like a good change, but I'm curious why you also changed the output string to no longer include the leading and trailing { }?

I asked about this some time ago in core channel and got the impression that there was a conclusion that the {} braces are redundant. I am happy to drop that change if you think they are useful.

@travisdowns
Copy link
Member

I asked about this some time ago in core channel and got the impression that there was a conclusion that the {} braces are redundant. I am happy to drop that change if you think they are useful.

No idea really, just didn't see any note about in the commit so I was curious.

LGTM, but maybe amend the message to note why you made this change?

travisdowns
travisdowns previously approved these changes Feb 27, 2024
Dropped curly braces that all named types were wrapped with when printed
to string.

The curly braces that the string representation of `named_type` are
redundant and were often on purpose dropped by accessing the underlying
value while printing the `named_type`.

With this chance we are going to reduce the verbosity of log messages
and make them easier to read.

Signed-off-by: Michal Maslanka <michal@redpanda.com>
@michael-redpanda
Copy link
Contributor

This looks fine, but I think future versions of libfmt may start to require a formatter specialization that inherits from ostream_formatter: https://fmt.dev/latest/api.html#std-ostream-support

@BenPope I think understands this a little bit more than I do

@vbotbuildovich
Copy link
Collaborator

vbotbuildovich commented Feb 27, 2024

@mmaslankaprv mmaslankaprv merged commit 182e420 into redpanda-data:dev Feb 29, 2024
16 checks passed
@mmaslankaprv mmaslankaprv deleted the named-type-formatting branch February 29, 2024 07:01
@BenPope
Copy link
Member

BenPope commented Feb 29, 2024

This looks fine, but I think future versions of libfmt may start to require a formatter specialization that inherits from ostream_formatter: https://fmt.dev/latest/api.html#std-ostream-support

That change is going to be vast, this has little bearing on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants