summaryrefslogtreecommitdiffstats
path: root/vendor/tracing-core/src/field.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/tracing-core/src/field.rs')
-rw-r--r--vendor/tracing-core/src/field.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/vendor/tracing-core/src/field.rs b/vendor/tracing-core/src/field.rs
index c9869ce2c..e103c75a9 100644
--- a/vendor/tracing-core/src/field.rs
+++ b/vendor/tracing-core/src/field.rs
@@ -145,6 +145,16 @@ pub struct Field {
pub struct Empty;
/// Describes the fields present on a span.
+///
+/// ## Equality
+///
+/// In well-behaved applications, two `FieldSet`s [initialized] with equal
+/// [callsite identifiers] will have identical fields. Consequently, in release
+/// builds, [`FieldSet::eq`] *only* checks that its arguments have equal
+/// callsites. However, the equality of field names is checked in debug builds.
+///
+/// [initialized]: Self::new
+/// [callsite identifiers]: callsite::Identifier
pub struct FieldSet {
/// The names of each field on the described span.
names: &'static [&'static str],
@@ -911,6 +921,40 @@ impl fmt::Display for FieldSet {
}
}
+impl Eq for FieldSet {}
+
+impl PartialEq for FieldSet {
+ fn eq(&self, other: &Self) -> bool {
+ if core::ptr::eq(&self, &other) {
+ true
+ } else if cfg!(not(debug_assertions)) {
+ // In a well-behaving application, two `FieldSet`s can be assumed to
+ // be totally equal so long as they share the same callsite.
+ self.callsite == other.callsite
+ } else {
+ // However, when debug-assertions are enabled, do NOT assume that
+ // the application is well-behaving; check every the field names of
+ // each `FieldSet` for equality.
+
+ // `FieldSet` is destructured here to ensure a compile-error if the
+ // fields of `FieldSet` change.
+ let Self {
+ names: lhs_names,
+ callsite: lhs_callsite,
+ } = self;
+
+ let Self {
+ names: rhs_names,
+ callsite: rhs_callsite,
+ } = &other;
+
+ // Check callsite equality first, as it is probably cheaper to do
+ // than str equality.
+ lhs_callsite == rhs_callsite && lhs_names == rhs_names
+ }
+ }
+}
+
// ===== impl Iter =====
impl Iterator for Iter {