Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add as_str to Version type #777

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

Open
itsibitzi wants to merge 1 commit into hyperium:master
base: master
Choose a base branch
Loading
from itsibitzi:sc-20250813-version-as-str

Conversation

@itsibitzi
Copy link

@itsibitzi itsibitzi commented Aug 13, 2025

Stringifications of the variants of the Version are known at compile time so requiring a Debug format is not necessary.

This is nice for me specifically because I want to record the HTTP version of queries using metrics crate. This crate allows users to record labels as either a String or &'static str, and given I didn't want to allocate a String with the Debug format I had to copy-paste the lookup.

Variants of Version are known at compile time
so requiring a Debug format is not necessary.
Copy link
Member

Thanks for the PR!

My feeling is that an as_str() doesn't fit semantically. Is there some sort of true string representation of a Version? I don't think there is.

The way I would solve this myself in another crate is to just match and return some static strings that make sense for my metrics.

Copy link
Author

itsibitzi commented Aug 17, 2025
edited
Loading

Yep, I'm doing the match statement right now. :)

I thought it might be useful for others to have access to the mapping currently within debug, but statically. The RFCs standardizing HTTP seem to use the HTTP/xyz format so I felt that was a canonical-enough form and would save some folks writing (admittedly a small amount of) boiler plate. Though I do note that the previous Debug implementation referred to HTTP/2 as HTTP/2.0, and similar for HTTP/3, which is not what the RFC used. This could be corrected either in both or just in an as_str version.

The function doesn't need to be called as_str, I suppose, but I'm not sure what would be a better name that would be easy for people to find. as_rfc_name? as_name?

stepancheg reacted with thumbs up emoji

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

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /