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

Fix PartialEq for Value in opentelemetry-stdout #1955

Merged
merged 3 commits into from
Jul 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions opentelemetry-stdout/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,21 @@

impl PartialEq for Value {
fn eq(&self, other: &Self) -> bool {
match (&self, &other) {
match (self, other) {
(Value::Bool(b), Value::Bool(ob)) => b.eq(ob),
(Value::Int(i), Value::Int(oi)) => i.eq(oi),

Check warning on line 91 in opentelemetry-stdout/src/common.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-stdout/src/common.rs#L89-L91

Added lines #L89 - L91 were not covered by tests
(Value::Double(f), Value::Double(of)) => OrderedFloat(*f).eq(&OrderedFloat(*of)),
(non_double, other_non_double) => non_double.eq(other_non_double),
(Value::String(s), Value::String(os)) => s.eq(os),
(Value::Array(a), Value::Array(oa)) => a.eq(oa),
(Value::KeyValues(kv), Value::KeyValues(okv)) => kv.eq(okv),
(Value::BytesValue(b), Value::BytesValue(ob)) => b.eq(ob),
(Value::Bool(_), _) => false,
Copy link
Contributor

Choose a reason for hiding this comment

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

Use a simpler wild card pattern instead?

_ => false,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My concern was that if a new variant were added to Value, PartialEq would compile but have an incorrect result. With this version, there would be a compile error. But if you favor conciseness, I can change.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point!

(Value::Int(_), _) => false,
(Value::Double(_), _) => false,
(Value::String(_), _) => false,
(Value::Array(_), _) => false,
(Value::KeyValues(_), _) => false,
(Value::BytesValue(_), _) => false,

Check warning on line 103 in opentelemetry-stdout/src/common.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-stdout/src/common.rs#L93-L103

Added lines #L93 - L103 were not covered by tests
}
}
}
Expand Down
Loading