-
Notifications
You must be signed in to change notification settings - Fork 727
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
tracing-core: implement PartialEq
, Eq
for Metadata
, FieldSet
#2229
Conversation
A `FieldSet` is equal to another `FieldSet` if they share the same callsite and fields (provided in the same order). This ensures that a `Field` applicable to one `FieldSet` is applicable to any equal `FieldSet`. A `Metadata` is equal to another `Metadata` if all of their contained metadata is exactly equal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm fine with this change, modulo some minor docs nits. thank you!
tracing-core/src/metadata.rs
Outdated
@@ -57,6 +46,7 @@ use core::{ | |||
/// [module path]: Self::module_path | |||
/// [collector]: super::collect::Collect | |||
/// [callsite identifier]: super::callsite::Identifier | |||
#[derive(Eq, PartialEq)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we may want a hand-written equality implementation for Metadata
s so that we can compare the callsite identifier first, and short-circuit so that we don't have to do a bunch of string equality. i believe the derived PartialEq
impl will compare fields in the order that they are declared.
that change could be made later as an optimization, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, i believe the derived implementations also generate an implementation of the StructuralPartialEq
trait, which allows matching a type as a match pattern (which is possible in v0.1.x of tracing-core
, where Metadata
's fields are pub
). this means that a change from a hand-written implementation to a derived one is potentially a breaking change...
This change manually re-implements `PartialEq` and `Eq` for `Metadata` and `FieldSet` to define their equality strictly in terms of callsite equality. In debug builds, the equality of these types' other fields is also checked. Documentation is added to both `Metadata` and `FieldSet` explaining this behavior. The expectation that, in a well-behaving application, `Metadata` and `FieldSet`s with equal callsites will be otherwise equal is documented on `Callsite::metadata`. This is not a breaking change, as previous releases did not define equality for `Metadata` or `FieldSet`. The `Callsite` trait remains safe, as this expectation is not (yet) a safety-critical property.
@hawkw I went a little beyond your comments, and re-implemented |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, this looks good to me --- i think the hand-written equality implementations seem correct and should hopefully be more efficient than the derived ones.
thanks again for your work on this!
A `FieldSet` is equal to another `FieldSet` if they share the same callsite and fields (provided in the same order). This ensures that a `Field` applicable to one `FieldSet` is applicable to any equal `FieldSet`. A `Metadata` is equal to another `Metadata` if all of their contained metadata is exactly equal. This change manually re-implements `PartialEq` and `Eq` for `Metadata` and `FieldSet` to define their equality strictly in terms of callsite equality. In debug builds, the equality of these types' other fields is also checked. Documentation is added to both `Metadata` and `FieldSet` explaining this behavior. The expectation that, in a well-behaving application, `Metadata` and `FieldSet`s with equal callsites will be otherwise equal is documented on `Callsite::metadata`. This is not a breaking change, as previous releases did not define equality for `Metadata` or `FieldSet`. The `Callsite` trait remains safe, as this expectation is not (yet) a safety-critical property.
A `FieldSet` is equal to another `FieldSet` if they share the same callsite and fields (provided in the same order). This ensures that a `Field` applicable to one `FieldSet` is applicable to any equal `FieldSet`. A `Metadata` is equal to another `Metadata` if all of their contained metadata is exactly equal. This change manually re-implements `PartialEq` and `Eq` for `Metadata` and `FieldSet` to define their equality strictly in terms of callsite equality. In debug builds, the equality of these types' other fields is also checked. Documentation is added to both `Metadata` and `FieldSet` explaining this behavior. The expectation that, in a well-behaving application, `Metadata` and `FieldSet`s with equal callsites will be otherwise equal is documented on `Callsite::metadata`. This is not a breaking change, as previous releases did not define equality for `Metadata` or `FieldSet`. The `Callsite` trait remains safe, as this expectation is not (yet) a safety-critical property.
A `FieldSet` is equal to another `FieldSet` if they share the same callsite and fields (provided in the same order). This ensures that a `Field` applicable to one `FieldSet` is applicable to any equal `FieldSet`. A `Metadata` is equal to another `Metadata` if all of their contained metadata is exactly equal. This change manually re-implements `PartialEq` and `Eq` for `Metadata` and `FieldSet` to define their equality strictly in terms of callsite equality. In debug builds, the equality of these types' other fields is also checked. Documentation is added to both `Metadata` and `FieldSet` explaining this behavior. The expectation that, in a well-behaving application, `Metadata` and `FieldSet`s with equal callsites will be otherwise equal is documented on `Callsite::metadata`. This is not a breaking change, as previous releases did not define equality for `Metadata` or `FieldSet`. The `Callsite` trait remains safe, as this expectation is not (yet) a safety-critical property.
# 0.1.29 (July 29, 2022) This release of `tracing-core` adds `PartialEq` and `Eq` implementations for metadata types, and improves error messages when setting the global default subscriber fails. ### Added - `PartialEq` and `Eq` implementations for `Metadata` ([#2229]) - `PartialEq` and `Eq` implementations for `FieldSet` ([#2229]) ### Fixed - Fixed unhelpful `fmt::Debug` output for `dispatcher::SetGlobalDefaultError` ([#2250]) - Fixed compilation with `-Z minimal-versions` ([#2246]) Thanks to @jswrenn and @CAD97 for contributing to this release! [#2229]: #2229 [#2246]: #2246 [#2250]: #2250
# 0.1.29 (July 29, 2022) This release of `tracing-core` adds `PartialEq` and `Eq` implementations for metadata types, and improves error messages when setting the global default subscriber fails. ### Added - `PartialEq` and `Eq` implementations for `Metadata` ([#2229]) - `PartialEq` and `Eq` implementations for `FieldSet` ([#2229]) ### Fixed - Fixed unhelpful `fmt::Debug` output for `dispatcher::SetGlobalDefaultError` ([#2250]) - Fixed compilation with `-Z minimal-versions` ([#2246]) Thanks to @jswrenn and @CAD97 for contributing to this release! [#2229]: #2229 [#2246]: #2246 [#2250]: #2250
# 0.1.29 (July 29, 2022) This release of `tracing-core` adds `PartialEq` and `Eq` implementations for metadata types, and improves error messages when setting the global default subscriber fails. ### Added - `PartialEq` and `Eq` implementations for `Metadata` ([tokio-rs#2229]) - `PartialEq` and `Eq` implementations for `FieldSet` ([tokio-rs#2229]) ### Fixed - Fixed unhelpful `fmt::Debug` output for `dispatcher::SetGlobalDefaultError` ([tokio-rs#2250]) - Fixed compilation with `-Z minimal-versions` ([tokio-rs#2246]) Thanks to @jswrenn and @CAD97 for contributing to this release! [tokio-rs#2229]: tokio-rs#2229 [tokio-rs#2246]: tokio-rs#2246 [tokio-rs#2250]: tokio-rs#2250
This change manually re-implements
PartialEq
andEq
forMetadata
andFieldSet
to define their equality strictly interms of callsite equality. In debug builds, the equality of
these types' other fields is also checked.
Documentation is added to both
Metadata
andFieldSet
explaining this behavior. The expectation that, in a well-behaving
application,
Metadata
andFieldSet
s with equal callsites will beotherwise equal is documented on
Callsite::metadata
. This is nota breaking change, as previous releases did not define equality for
Metadata
orFieldSet
. TheCallsite
trait remains safe, as thisexpectation is not (yet) a safety-critical property.
This change improves the ergonomics of comparing
Metadata
, whichis very useful for testing and user-facing examples.