ptr

package
v0.0.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 17, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(p *bool) bool

Bool returns the value of a bool pointer or false if nil.

func BoolSlice

func BoolSlice(p []*bool) []bool

BoolSlice converts a slice of bool pointers to a slice of bools. Nil pointers are converted to false. Returns nil for nil input.

func Byte

func Byte(p *byte) byte

Byte returns the value of a byte pointer or 0 if nil.

func ByteSlice

func ByteSlice(p []*byte) []byte

ByteSlice converts a slice of byte pointers to a slice of bytes. Nil pointers are converted to 0. Returns nil for nil input.

func Complex128

func Complex128(p *complex128) complex128

Complex128 returns the value of a complex128 pointer or 0+0i if nil.

func Complex128Slice

func Complex128Slice(p []*complex128) []complex128

Complex128Slice converts a slice of complex128 pointers to a slice of complex128s. Nil pointers are converted to 0+0i. Returns nil for nil input.

func Complex64

func Complex64(p *complex64) complex64

Complex64 returns the value of a complex64 pointer or 0+0i if nil.

func Complex64Slice

func Complex64Slice(p []*complex64) []complex64

Complex64Slice converts a slice of complex64 pointers to a slice of complex64s. Nil pointers are converted to 0+0i. Returns nil for nil input.

func Duration

func Duration(p *time.Duration) time.Duration

Duration returns the value of a time.Duration pointer or zero duration if nil.

func DurationSlice

func DurationSlice(p []*time.Duration) []time.Duration

DurationSlice converts a slice of time.Duration pointers to a slice of time.Durations. Nil pointers are converted to zero duration. Returns nil for nil input.

func Float32

func Float32(p *float32) float32

Float32 returns the value of a float32 pointer or 0.0 if nil.

func Float32Slice

func Float32Slice(p []*float32) []float32

Float32Slice converts a slice of float32 pointers to a slice of float32s. Nil pointers are converted to 0.0. Returns nil for nil input.

func Float64

func Float64(p *float64) float64

Float64 returns the value of a float64 pointer or 0.0 if nil.

func Float64Slice

func Float64Slice(p []*float64) []float64

Float64Slice converts a slice of float64 pointers to a slice of float64s. Nil pointers are converted to 0.0. Returns nil for nil input.

func Int

func Int(p *int) int

Int returns the value of an int pointer or 0 if nil.

func Int16

func Int16(p *int16) int16

Int16 returns the value of an int16 pointer or 0 if nil.

func Int16Slice

func Int16Slice(p []*int16) []int16

Int16Slice converts a slice of int16 pointers to a slice of int16s. Nil pointers are converted to 0. Returns nil for nil input.

func Int32

func Int32(p *int32) int32

Int32 returns the value of an int32 pointer or 0 if nil.

func Int32Slice

func Int32Slice(p []*int32) []int32

Int32Slice converts a slice of int32 pointers to a slice of int32s. Nil pointers are converted to 0. Returns nil for nil input.

func Int64

func Int64(p *int64) int64

Int64 returns the value of an int64 pointer or 0 if nil.

func Int64Slice

func Int64Slice(p []*int64) []int64

Int64Slice converts a slice of int64 pointers to a slice of int64s. Nil pointers are converted to 0. Returns nil for nil input.

func Int8

func Int8(p *int8) int8

Int8 returns the value of an int8 pointer or 0 if nil.

func Int8Slice

func Int8Slice(p []*int8) []int8

Int8Slice converts a slice of int8 pointers to a slice of int8s. Nil pointers are converted to 0. Returns nil for nil input.

func IntSlice

func IntSlice(p []*int) []int

IntSlice converts a slice of int pointers to a slice of ints. Nil pointers are converted to 0. Returns nil for nil input.

func NonNilBoolSlice

func NonNilBoolSlice(p []*bool) []bool

NonNilBoolSlice is like BoolSlice but returns empty slice instead of nil for nil input.

func NonNilByteSlice

func NonNilByteSlice(p []*byte) []byte

NonNilByteSlice is like ByteSlice but returns empty slice instead of nil for nil input.

func NonNilComplex128Slice

func NonNilComplex128Slice(p []*complex128) []complex128

NonNilComplex128Slice is like Complex128Slice but returns empty slice instead of nil for nil input.

func NonNilComplex64Slice

func NonNilComplex64Slice(p []*complex64) []complex64

NonNilComplex64Slice is like Complex64Slice but returns empty slice instead of nil for nil input.

func NonNilDurationSlice

func NonNilDurationSlice(p []*time.Duration) []time.Duration

NonNilDurationSlice is like DurationSlice but returns empty slice instead of nil for nil input.

func NonNilFloat32Slice

func NonNilFloat32Slice(p []*float32) []float32

NonNilFloat32Slice is like Float32Slice but returns empty slice instead of nil for nil input.

func NonNilFloat64Slice

func NonNilFloat64Slice(p []*float64) []float64

NonNilFloat64Slice is like Float64Slice but returns empty slice instead of nil for nil input.

func NonNilInt16Slice

func NonNilInt16Slice(p []*int16) []int16

NonNilInt16Slice is like Int16Slice but returns empty slice instead of nil for nil input.

func NonNilInt32Slice

func NonNilInt32Slice(p []*int32) []int32

NonNilInt32Slice is like Int32Slice but returns empty slice instead of nil for nil input.

func NonNilInt64Slice

func NonNilInt64Slice(p []*int64) []int64

NonNilInt64Slice is like Int64Slice but returns empty slice instead of nil for nil input.

func NonNilInt8Slice

func NonNilInt8Slice(p []*int8) []int8

NonNilInt8Slice is like Int8Slice but returns empty slice instead of nil for nil input.

func NonNilIntSlice

func NonNilIntSlice(p []*int) []int

NonNilIntSlice is like IntSlice but returns empty slice instead of nil for nil input.

func NonNilRuneSlice

func NonNilRuneSlice(p []*rune) []rune

NonNilRuneSlice is like RuneSlice but returns empty slice instead of nil for nil input.

func NonNilSliceValue

func NonNilSliceValue[T any](p []*T, defaultValue T) []T

NonNilSliceValue is like SliceValue but returns empty slice instead of nil for nil input.

func NonNilStringSlice

func NonNilStringSlice(p []*string) []string

NonNilStringSlice is like StringSlice but returns empty slice instead of nil for nil input.

func NonNilTimeSlice

func NonNilTimeSlice(p []*time.Time) []time.Time

NonNilTimeSlice is like TimeSlice but returns empty slice instead of nil for nil input.

func NonNilUint16Slice

func NonNilUint16Slice(p []*uint16) []uint16

NonNilUint16Slice is like Uint16Slice but returns empty slice instead of nil for nil input.

func NonNilUint32Slice

func NonNilUint32Slice(p []*uint32) []uint32

NonNilUint32Slice is like Uint32Slice but returns empty slice instead of nil for nil input.

func NonNilUint64Slice

func NonNilUint64Slice(p []*uint64) []uint64

NonNilUint64Slice is like Uint64Slice but returns empty slice instead of nil for nil input.

func NonNilUint8Slice

func NonNilUint8Slice(p []*uint8) []uint8

NonNilUint8Slice is like Uint8Slice but returns empty slice instead of nil for nil input.

func NonNilUintSlice

func NonNilUintSlice(p []*uint) []uint

NonNilUintSlice is like UintSlice but returns empty slice instead of nil for nil input.

func Rune

func Rune(p *rune) rune

Rune returns the value of a rune pointer or 0 if nil.

func RuneSlice

func RuneSlice(p []*rune) []rune

RuneSlice converts a slice of rune pointers to a slice of runes. Nil pointers are converted to 0. Returns nil for nil input.

func SliceValue

func SliceValue[T any](p []*T, defaultValue T) []T

SliceValue converts a slice of pointers to a slice of values. If a pointer in the slice is nil, defaultValue is used for that element. Returns nil if input slice is nil.

func String

func String(p *string) string

String returns the value of a string pointer or empty string if nil.

func StringSlice

func StringSlice(p []*string) []string

StringSlice converts a slice of string pointers to a slice of strings. Nil pointers are converted to empty strings. Returns nil for nil input.

func Time

func Time(p *time.Time) time.Time

Time returns the value of a time.Time pointer or zero time if nil.

func TimeSlice

func TimeSlice(p []*time.Time) []time.Time

TimeSlice converts a slice of time.Time pointers to a slice of time.Times. Nil pointers are converted to zero time. Returns nil for nil input.

func ToBool

func ToBool(v bool) *bool

ToBool converts a bool to a bool pointer.

func ToBoolSlice

func ToBoolSlice(v []bool) []*bool

ToBoolSlice converts a slice of bools to a slice of bool pointers. Returns nil if input slice is nil.

func ToByte

func ToByte(v byte) *byte

ToByte converts a byte to a byte pointer.

func ToByteSlice

func ToByteSlice(v []byte) []*byte

ToByteSlice converts a slice of bytes to a slice of byte pointers. Returns nil if input slice is nil.

func ToComplex128

func ToComplex128(v complex128) *complex128

ToComplex128 converts a complex128 to a complex128 pointer.

func ToComplex128Slice

func ToComplex128Slice(v []complex128) []*complex128

ToComplex128Slice converts a slice of complex128s to a slice of complex128 pointers. Returns nil if input slice is nil.

func ToComplex64

func ToComplex64(v complex64) *complex64

ToComplex64 converts a complex64 to a complex64 pointer.

func ToComplex64Slice

func ToComplex64Slice(v []complex64) []*complex64

ToComplex64Slice converts a slice of complex64s to a slice of complex64 pointers. Returns nil if input slice is nil.

func ToDuration

func ToDuration(v time.Duration) *time.Duration

ToDuration converts a time.Duration to a time.Duration pointer.

func ToDurationSlice

func ToDurationSlice(v []time.Duration) []*time.Duration

ToDurationSlice converts a slice of time.Durations to a slice of time.Duration pointers. Returns nil if input slice is nil.

func ToFloat32

func ToFloat32(v float32) *float32

ToFloat32 converts a float32 to a float32 pointer.

func ToFloat32Slice

func ToFloat32Slice(v []float32) []*float32

ToFloat32Slice converts a slice of float32s to a slice of float32 pointers. Returns nil if input slice is nil.

func ToFloat64

func ToFloat64(v float64) *float64

ToFloat64 converts a float64 to a float64 pointer.

func ToFloat64Slice

func ToFloat64Slice(v []float64) []*float64

ToFloat64Slice converts a slice of float64s to a slice of float64 pointers. Returns nil if input slice is nil.

func ToInt

func ToInt(v int) *int

ToInt converts an int to an int pointer.

func ToInt16

func ToInt16(v int16) *int16

ToInt16 converts an int16 to an int16 pointer.

func ToInt16Slice

func ToInt16Slice(v []int16) []*int16

ToInt16Slice converts a slice of int16s to a slice of int16 pointers. Returns nil if input slice is nil.

func ToInt32

func ToInt32(v int32) *int32

ToInt32 converts an int32 to an int32 pointer.

func ToInt32Slice

func ToInt32Slice(v []int32) []*int32

ToInt32Slice converts a slice of int32s to a slice of int32 pointers. Returns nil if input slice is nil.

func ToInt64

func ToInt64(v int64) *int64

ToInt64 converts an int64 to an int64 pointer.

func ToInt64Slice

func ToInt64Slice(v []int64) []*int64

ToInt64Slice converts a slice of int64s to a slice of int64 pointers. Returns nil if input slice is nil.

func ToInt8

func ToInt8(v int8) *int8

ToInt8 converts an int8 to an int8 pointer.

func ToInt8Slice

func ToInt8Slice(v []int8) []*int8

ToInt8Slice converts a slice of int8s to a slice of int8 pointers. Returns nil if input slice is nil.

func ToIntSlice

func ToIntSlice(v []int) []*int

ToIntSlice converts a slice of ints to a slice of int pointers. Returns nil if input slice is nil.

func ToPointer

func ToPointer[T any](v T) *T

ToPointer converts a value of type T to a pointer.

func ToRune

func ToRune(v rune) *rune

ToRune converts a rune to a rune pointer.

func ToRuneSlice

func ToRuneSlice(v []rune) []*rune

ToRuneSlice converts a slice of runes to a slice of rune pointers. Returns nil if input slice is nil.

func ToSlicePointer

func ToSlicePointer[T any](v []T) []*T

ToSlicePointer converts a slice of values to a slice of pointers. Returns nil if input slice is nil.

func ToString

func ToString(v string) *string

ToString converts a string to a string pointer.

func ToStringSlice

func ToStringSlice(v []string) []*string

ToStringSlice converts a slice of strings to a slice of string pointers. Returns nil if input slice is nil.

func ToTime

func ToTime(v time.Time) *time.Time

ToTime converts a time.Time to a time.Time pointer.

func ToTimeSlice

func ToTimeSlice(v []time.Time) []*time.Time

ToTimeSlice converts a slice of time.Times to a slice of time.Time pointers. Returns nil if input slice is nil.

func ToUint

func ToUint(v uint) *uint

ToUint converts a uint to a uint pointer.

func ToUint16

func ToUint16(v uint16) *uint16

ToUint16 converts a uint16 to a uint16 pointer.

func ToUint16Slice

func ToUint16Slice(v []uint16) []*uint16

ToUint16Slice converts a slice of uint16s to a slice of uint16 pointers. Returns nil if input slice is nil.

func ToUint32

func ToUint32(v uint32) *uint32

ToUint32 converts a uint32 to a uint32 pointer.

func ToUint32Slice

func ToUint32Slice(v []uint32) []*uint32

ToUint32Slice converts a slice of uint32s to a slice of uint32 pointers. Returns nil if input slice is nil.

func ToUint64

func ToUint64(v uint64) *uint64

ToUint64 converts a uint64 to a uint64 pointer.

func ToUint64Slice

func ToUint64Slice(v []uint64) []*uint64

ToUint64Slice converts a slice of uint64s to a slice of uint64 pointers. Returns nil if input slice is nil.

func ToUint8

func ToUint8(v uint8) *uint8

ToUint8 converts a uint8 to a uint8 pointer.

func ToUint8Slice

func ToUint8Slice(v []uint8) []*uint8

ToUint8Slice converts a slice of uint8s to a slice of uint8 pointers. Returns nil if input slice is nil.

func ToUintSlice

func ToUintSlice(v []uint) []*uint

ToUintSlice converts a slice of uints to a slice of uint pointers. Returns nil if input slice is nil.

func Uint

func Uint(p *uint) uint

Uint returns the value of a uint pointer or 0 if nil.

func Uint16

func Uint16(p *uint16) uint16

Uint16 returns the value of a uint16 pointer or 0 if nil.

func Uint16Slice

func Uint16Slice(p []*uint16) []uint16

Uint16Slice converts a slice of uint16 pointers to a slice of uint16s. Nil pointers are converted to 0. Returns nil for nil input.

func Uint32

func Uint32(p *uint32) uint32

Uint32 returns the value of a uint32 pointer or 0 if nil.

func Uint32Slice

func Uint32Slice(p []*uint32) []uint32

Uint32Slice converts a slice of uint32 pointers to a slice of uint32s. Nil pointers are converted to 0. Returns nil for nil input.

func Uint64

func Uint64(p *uint64) uint64

Uint64 returns the value of a uint64 pointer or 0 if nil.

func Uint64Slice

func Uint64Slice(p []*uint64) []uint64

Uint64Slice converts a slice of uint64 pointers to a slice of uint64s. Nil pointers are converted to 0. Returns nil for nil input.

func Uint8

func Uint8(p *uint8) uint8

Uint8 returns the value of a uint8 pointer or 0 if nil.

func Uint8Slice

func Uint8Slice(p []*uint8) []uint8

Uint8Slice converts a slice of uint8 pointers to a slice of uint8s. Nil pointers are converted to 0. Returns nil for nil input.

func UintSlice

func UintSlice(p []*uint) []uint

UintSlice converts a slice of uint pointers to a slice of uints. Nil pointers are converted to 0. Returns nil for nil input.

func Value

func Value[T any](p *T, defaultValue T) T

Value dereferences a pointer and returns its value. If the pointer is nil, it returns the specified defaultValue.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL