Documentation ¶
Overview ¶
Package pointy is a set of simple helper functions to provide a shorthand to get a pointer to a variable holding a constant.
Index ¶
- func Bool(x bool) *bool
- func BoolValue(p *bool, fallback bool) bool
- func Byte(x byte) *byte
- func ByteValue(p *byte, fallback byte) byte
- func Complex128(x complex128) *complex128
- func Complex128Value(p *complex128, fallback complex128) complex128
- func Complex64(x complex64) *complex64
- func Complex64Value(p *complex64, fallback complex64) complex64
- func Float32(x float32) *float32
- func Float32Value(p *float32, fallback float32) float32
- func Float64(x float64) *float64
- func Float64Value(p *float64, fallback float64) float64
- func Int(x int) *int
- func Int16(x int16) *int16
- func Int16Value(p *int16, fallback int16) int16
- func Int32(x int32) *int32
- func Int32Value(p *int32, fallback int32) int32
- func Int64(x int64) *int64
- func Int64Value(p *int64, fallback int64) int64
- func Int8(x int8) *int8
- func Int8Value(p *int8, fallback int8) int8
- func IntValue(p *int, fallback int) int
- func Pointer[T any](x T) *T
- func PointerValue[T any](p *T, fallback T) T
- func PointerValueEqual[T comparable](a *T, b T) bool
- func PointersValueEqual[T comparable](a *T, b *T) bool
- func Rune(x rune) *rune
- func RuneValue(p *rune, fallback rune) rune
- func String(x string) *string
- func StringValue(p *string, fallback string) string
- func Uint(x uint) *uint
- func Uint16(x uint16) *uint16
- func Uint16Value(p *uint16, fallback uint16) uint16
- func Uint32(x uint32) *uint32
- func Uint32Value(p *uint32, fallback uint32) uint32
- func Uint64(x uint64) *uint64
- func Uint64Value(p *uint64, fallback uint64) uint64
- func Uint8(x uint8) *uint8
- func Uint8Value(p *uint8, fallback uint8) uint8
- func UintValue(p *uint, fallback uint) uint
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Complex128 ¶
func Complex128(x complex128) *complex128
Complex128 returns a pointer to a variable holding the supplied complex128 constant
func Complex128Value ¶
func Complex128Value(p *complex128, fallback complex128) complex128
Complex128Value returns the complex128 value pointed to by p or fallback if p is nil
func Complex64Value ¶
Complex64Value returns the complex64 value pointed to by p or fallback if p is nil
func Float32Value ¶
Float32Value returns the float32 value pointed to by p or fallback if p is nil
func Float64Value ¶
Float64Value returns the float64 value pointed to by p or fallback if p is nil
func Int16Value ¶
Int16Value returns the int16 value pointed to by p or fallback if p is nil
func Int32Value ¶
Int32Value returns the int32 value pointed to by p or fallback if p is nil
func Int64 ¶
Int64 returns a pointer to a variable holding the supplied int64 constant
Example ¶
This example returns a pointer to a variable holding the `int64` constant `2018`.
package main import ( "fmt" "github.com/openlyinc/pointy" ) func main() { foo := pointy.Int64(2018) fmt.Println("foo contains value:", *foo) }
Output:
func Int64Value ¶
Int64Value returns the int64 value pointed to by p or fallback if p is nil
func Pointer ¶ added in v1.2.0
func Pointer[T any](x T) *T
Pointer returns a pointer to a variable holding the supplied T constant
Example ¶
This example uses the new generic construct to returns a pointer to a variable holding the `string` constant "point to me".
package main import ( "fmt" "github.com/openlyinc/pointy" ) func main() { foo := pointy.Pointer("point to me") fmt.Println("foo contains value:", *foo) }
Output:
func PointerValue ¶ added in v1.2.0
func PointerValue[T any](p *T, fallback T) T
PointerValue returns the T value pointed to by p or fallback if p is nil
func PointerValueEqual ¶ added in v1.2.0
func PointerValueEqual[T comparable](a *T, b T) bool
PointerValueEqual returns true if the pointer parameter is not nil and contains the same dereferenced value as the value parameter.
Example ¶
This example demonstrates comparing a pointer to a value using dereferenced value equality.
package main import ( "fmt" "github.com/openlyinc/pointy" ) func main() { a := pointy.Int(1) b := 1 if pointy.PointerValueEqual(a, b) { fmt.Println("a and b contain equal dereferenced values") } }
Output:
func PointersValueEqual ¶ added in v1.2.0
func PointersValueEqual[T comparable](a *T, b *T) bool
PointersValueEqual returns true if both pointer parameters are nil or contain the same dereferenced value.
Example ¶
This example demonstrates comparing two pointers using dereferenced value equality.
package main import ( "fmt" "github.com/openlyinc/pointy" ) func main() { a := pointy.Int(1) b := pointy.Int(1) if pointy.PointersValueEqual(a, b) { fmt.Println("a and b contain equal dereferenced values") } }
Output:
func String ¶
String returns a pointer to a variable holding the supplied string constant
Example ¶
This example returns a pointer to a variable holding the `string` constant "point to me".
package main import ( "fmt" "github.com/openlyinc/pointy" ) func main() { bar := pointy.String("point to me") fmt.Println("bar contains value:", *bar) }
Output:
func StringValue ¶
StringValue returns the string value pointed to by p or fallback if p is nil
func Uint16Value ¶
Uint16Value returns the uint16 value pointed to by p or fallback if p is nil
func Uint32Value ¶
Uint32Value returns the uint32 value pointed to by p or fallback if p is nil
func Uint64Value ¶
Uint64Value returns the uint64 value pointed to by p or fallback if p is nil
func Uint8Value ¶
Uint8Value returns the uint8 value pointed to by p or fallback if p is nil
Types ¶
This section is empty.