ptr

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2025 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package ptr provides value to pointer and pointer to value functions.

In most cases, simply use ptr.To or ptr.From functions. There are some extra functions for types which would normally need type conversions from constants, such as ptr.ToInt64.

Package ptr provides utility functions for working with pointers in Go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmptyToNil

func EmptyToNil[T comparable](value *T) *T

EmptyToNil checks if the pointer is nil or if it points to a zero value of type T. If it is nil or points to a zero value, it returns nil. Otherwise, it returns a pointer to the value it points to.

func OrTo

func OrTo[T any](value *T, defaultValue T) *T

OrTo returns the pointer if not nil, else return a pointer to the default value.

func To

func To[T any](value T) *T

To returns a pointer to the given value.

func ToNilIfEmpty

func ToNilIfEmpty[T comparable](value T) *T

ToNilIfEmpty returns a pointer to the given value if it is not equal to the zero value of type T. If it is equal to the zero value, it returns nil.

func ValueOr

func ValueOr[T any](value *T, defaultValue T) T

ValueOr return value of pointer if not nil, else return default value.

func ValueOrEmpty

func ValueOrEmpty[T any](ref *T) (value T)

ValueOrEmpty returns the value from a given pointer. If ref is nil, a zero value of type T will be returned.

Types

This section is empty.

Jump to

Keyboard shortcuts

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