Skip to content

feat: derive PartialEq and Eq for MetricType and Unit - #366

Merged
krisztianfekete merged 4 commits into
prometheus:masterfrom
herin049:feat/metric-type-partial-eq
Nov 4, 2026
Merged

krisztianfekete merged 4 commits into
prometheus:masterfrom
herin049:feat/metric-type-partial-eq

Conversation

@herin049

@herin049 herin049 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Derive PartialEq and Eq for metrics::MetricType and registry::Unit, so they can be compared with ==/!=.

This is needed (not technically, but nice to have) to adopt the prometheus-client crate in opentelemetry-prometheus in open-telemetry/opentelemetry-rust which needs to compare these types.

Changes

  • MetricType: add PartialEq, Eq derives.
  • Unit: add PartialEq, Eq derives.

@herin049
herin049 force-pushed the feat/metric-type-partial-eq branch from de6a045 to 95144b8 Compare November 3, 2026 04:00
@herin049

herin049 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

cc: @krisztianfekete

@krisztianfekete krisztianfekete left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, this LGTM overall!
Two small things:

  • The new tests only check what #[derive] generates. Can you please drop them to keep the diff focused?
  • Optional: since you're touching these derives, would you also add Hash? It's cheap, it's in line with Rust's API guidelines on common traits, and it lets downstream code use MetricType/Unit as map keys. No strong opinion here, though.

Signed-off-by: Lukas Hering <lukasheringb@gmail.com>
Signed-off-by: Lukas Hering <lukasheringb@gmail.com>
Signed-off-by: Lukas Hering <lukasheringb@gmail.com>
Signed-off-by: Lukas Hering <lukasheringb@gmail.com>
@herin049
herin049 force-pushed the feat/metric-type-partial-eq branch from 107b577 to 5edd3b2 Compare November 3, 2026 18:21
@herin049

herin049 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, this LGTM overall! Two small things:

  • The new tests only check what #[derive] generates. Can you please drop them to keep the diff focused?
  • Optional: since you're touching these derives, would you also add Hash? It's cheap, it's in line with Rust's API guidelines on common traits, and it lets downstream code use MetricType/Unit as map keys. No strong opinion here, though.

Thanks @krisztianfekete! Dropped the tests and added Hash (I was also thinking of adding this 👍 )

@krisztianfekete krisztianfekete left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks!

@krisztianfekete
krisztianfekete added this pull request to the merge queue Nov 4, 2026
Merged via the queue into prometheus:master with commit 8d0346a Nov 4, 2026
11 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