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

feat: allow Arc<String> on EncodeLabelSet #217

Merged
merged 3 commits into from
Jul 29, 2024

Conversation

flaneur2020
Copy link
Contributor

@flaneur2020 flaneur2020 commented Jul 18, 2024

I'm writing a label struct like this:

#[derive(Debug, Clone, Hash, Eq, PartialEq, EncodeLabelSet)]
struct ErrorLabels {
    op: &'static str,
    scheme: &'static str,
    err: &'static str,
    root: Arc<String>,
    namespace: Arc<String>,
}

in this struct, the root and namespace field is nearly immutable after a client get established. i hope to use Arc to reduce copy Strings on updating metrics.

but i got this error:

the trait bound `for<'a> &'a std::string::String: EncodeLabelValue` is not satisfied
the trait `EncodeLabelValue` is implemented for `std::string::String`
required for `Arc<std::string::String>` to implement `EncodeLabelValue`

it tells that we need implement &String to EncodeLabelValue.

this PR addes a implement about EncodeLabelValue for &String, and it can make the previous labels struct compile successfully.

@flaneur2020 flaneur2020 force-pushed the add-arc-string branch 2 times, most recently from fa62e27 to f0b7946 Compare July 18, 2024 06:15
Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

Thanks!

Can you add a changelog entry in CHANGELOG.md?

Also, can you add a test in https://github.com/prometheus/client_rust/blob/master/derive-encode/tests/lib.rs

@flaneur2020
Copy link
Contributor Author

sure, i'll add the test and changelog in this pr!

Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

Thank you!

@mxinden mxinden merged commit 53f15ec into prometheus:master Jul 29, 2024
10 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