-
-
Notifications
You must be signed in to change notification settings - Fork 343
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
Conversation
Variants of Version are known at compile time so requiring a Debug format is not necessary.
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.
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?
Stringifications of the variants of the
Versionare known at compile time so requiring aDebugformat is not necessary.This is nice for me specifically because I want to record the HTTP version of queries using
metricscrate. This crate allows users to record labels as either aStringor&'static str, and given I didn't want to allocate aStringwith theDebugformat I had to copy-paste the lookup.