sugar/pointers.go

102 lines
2.1 KiB
Go
Raw Normal View History

2021-08-31 01:26:45 -04:00
// Package sugar provides convenience functions for keeping code clean and less repetitive.
2021-08-21 09:21:28 -04:00
package sugar
/*
* Literal Addressers
*/
2021-08-31 01:25:56 -04:00
// IntPtr takes an int literal and returns a pointer.
2021-08-21 09:21:28 -04:00
func IntPtr(v int) *int {
return &v
}
2021-08-31 01:25:56 -04:00
// Int8Ptr takes an int8 literal and returns a pointer.
2021-08-21 09:21:28 -04:00
func Int8Ptr(v int8) *int8 {
return &v
}
2021-08-31 01:25:56 -04:00
// Int16Ptr takes an int16 literal and returns a pointer.
2021-08-21 09:21:28 -04:00
func Int16Ptr(v int16) *int16 {
return &v
}
2021-08-31 01:25:56 -04:00
// Int32Ptr takes an int32 literal and returns a pointer.
2021-08-21 09:21:28 -04:00
func Int32Ptr(v int32) *int32 {
return &v
}
2021-08-31 01:25:56 -04:00
// RunePtr takes a rune literal and returns a pointer.
2021-08-21 09:21:28 -04:00
func RunePtr(v rune) *rune {
return &v
}
2021-08-31 01:25:56 -04:00
// Int64Ptr takes an int64 literal and returns a pointer.
2021-08-21 09:21:28 -04:00
func Int64Ptr(v int64) *int64 {
return &v
}
2021-08-31 01:25:56 -04:00
// UintPtr takes a uint literal and returns a pointer.
2021-08-21 09:21:28 -04:00
func UintPtr(v uint) *uint {
return &v
}
2021-08-31 01:25:56 -04:00
// Uint8 takes a uint8 literal and returns a pointer.
2021-08-21 09:21:28 -04:00
func Uint8Ptr(v uint8) *uint8 {
return &v
}
2021-08-31 01:25:56 -04:00
// BytePtr takes a byte literal and returns a pointer.
2021-08-21 09:21:28 -04:00
func BytePtr(v byte) *byte {
return &v
}
2021-08-31 01:25:56 -04:00
// Uint16Ptr takes a uint16 literal and returns a pointer.
2021-08-21 09:21:28 -04:00
func Uint16Ptr(v uint16) *uint16 {
return &v
}
2021-08-31 01:25:56 -04:00
// Uint32Ptr takes uint32 literal and returns a pointer.
2021-08-21 09:21:28 -04:00
func Uint32Ptr(v uint32) *uint32 {
return &v
}
2021-08-31 01:25:56 -04:00
// Uint64Ptr takes uint64 literal and returns a pointer.
2021-08-21 09:21:28 -04:00
func Uint64Ptr(v uint64) *uint64 {
return &v
}
2021-08-31 01:25:56 -04:00
// Float32Ptr takes float32 literal and returns a pointer.
2021-08-21 09:21:28 -04:00
func Float32Ptr(v float32) *float32 {
return &v
}
2021-08-31 01:25:56 -04:00
// Float64Ptr takes a float64 literal and returns a pointer.
2021-08-21 09:21:28 -04:00
func Float64Ptr(v float64) *float64 {
return &v
}
2021-08-31 01:25:56 -04:00
// Complex64Ptr takes a complex64 literal and returns a pointer.
2021-08-21 09:21:28 -04:00
func Complex64Ptr(v complex64) *complex64 {
return &v
}
2021-08-31 01:25:56 -04:00
// Complex128Ptr takes a complex128 literal and returns a pointer.
2021-08-21 09:21:28 -04:00
func Complex128Ptr(v complex128) *complex128 {
return &v
}
2021-08-31 01:25:56 -04:00
// StringPtr takes a string literal and returns a pointer.
2021-08-21 09:21:28 -04:00
func StringPtr(v string) *string {
return &v
}
2021-08-31 01:25:56 -04:00
// StrPtr is an alias of StringPtr.
2021-08-21 09:21:28 -04:00
func StrPtr(v string) *string {
return &v
}
2021-08-31 01:25:56 -04:00
// BoolPtr takes a bool literal and returns a pointer.
2021-08-21 09:21:28 -04:00
func BoolPtr(v bool) *bool {
return &v
}