Skip to content

Commit 9131de7

Browse files
committed
Document and check resource comparability
Ensure backwards compatibility by adding a compile-time check that the Resource remains comparable. Document the shortcomings of direct comparison of a Resource.
1 parent 0c62fd1 commit 9131de7

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

sdk/resource/resource.go

+9
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,20 @@ import (
2121
// Resources should be passed and stored as pointers
2222
// (`*resource.Resource`). The `nil` value is equivalent to an empty
2323
// Resource.
24+
//
25+
// While Resource is comparable, its comparison should not be relied on when
26+
// checking equality. The [Resource.Equal] method should be used to check
27+
// equality between two resources and the [attribute.Distinct] returned from
28+
// [Resource.Equivalent] should be used for map keys instead. No guantee of the
29+
// correctness of direct comparisons is provided.
2430
type Resource struct {
2531
attrs attribute.Set
2632
schemaURL string
2733
}
2834

35+
// Compile-time check that the Resource remains comparable.
36+
var _ map[Resource]struct{} = nil
37+
2938
var (
3039
defaultResource *Resource
3140
defaultResourceOnce sync.Once

0 commit comments

Comments
 (0)