pointers.go raw

   1  package pointers
   2  
   3  import (
   4  	"time"
   5  
   6  	"next.orly.dev/pkg/nostr/encoders/timestamp"
   7  )
   8  
   9  // PointerToValue is a generic interface (type constraint) to refer to any
  10  // pointer to almost any kind of common type of value.
  11  //
  12  // see the utils/values package for a set of methods to accept these values and
  13  // return the correct type pointer to them.
  14  type PointerToValue interface {
  15  	~*uint | ~*int | ~*uint8 | ~*uint16 | ~*uint32 | ~*uint64 | ~*int8 | ~*int16 | ~*int32 |
  16  		~*int64 | ~*float32 | ~*float64 | ~*string | ~*[]string | ~*time.Time | ~*time.Duration |
  17  		~*[]byte | ~*[][]byte | ~*timestamp.T
  18  }
  19  
  20  // Present determines whether there is a value for a PointerToValue type.
  21  func Present[V PointerToValue](i V) bool {
  22  	return i != nil
  23  }
  24