Use AsRef<str> for owned label values #537
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is somewhat related to #529, but it's not trying to achieve/solve the same thing.
For a few of our applications we get some label values (e.g. client ID, client type, IP address) during a protocol handshake. Once the connection is setup each connection has a session object that remains valid during the lifetime of the session. So we were looking for a way to store the connection specifiek values in either a map or a slice so we could use them with
vec.with(&session.labels)orvec.with_label_values(&session.label_values).But since the current implementation requires these maps or slices to only contain
&strvalues, this currently isn't possible without some additional hacks or workarounds which makes the code less clean and less efficient.Allowing values that implement
AsRef<str>(so you can useHashMap<&str, String>maps orVec<String>slices) solved this issue.P.S. The second commit only contains a few LSP and Clippy related fixes to silence any warnings. Let me know if that is OK, if not I will drop that commit!