github.com/terramate-io/tf@v0.0.0-20230830114523-fce866b4dfcd/addrs/unique_key.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package addrs
     5  
     6  // UniqueKey is an interface implemented by values that serve as unique map
     7  // keys for particular addresses.
     8  //
     9  // All implementations of UniqueKey are comparable and can thus be used as
    10  // map keys. Unique keys generated from different address types are always
    11  // distinct. All functionally-equivalent keys for the same address type
    12  // always compare equal, and likewise functionally-different values do not.
    13  type UniqueKey interface {
    14  	uniqueKeySigil()
    15  }
    16  
    17  // UniqueKeyer is an interface implemented by types that can be represented
    18  // by a unique key.
    19  //
    20  // Some address types naturally comply with the expectations of a UniqueKey
    21  // and may thus be their own unique key type. However, address types that
    22  // are not naturally comparable can implement this interface by returning
    23  // proxy values.
    24  type UniqueKeyer interface {
    25  	UniqueKey() UniqueKey
    26  }
    27  
    28  func Equivalent[T UniqueKeyer](a, b T) bool {
    29  	return a.UniqueKey() == b.UniqueKey()
    30  }