ptr

package
v0.0.0-...-0849a56 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 2 Imported by: 1,178

README

Pointer

This package provides some functions for pointer-based operations.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllPtrFieldsNil

func AllPtrFieldsNil(obj interface{}) bool

AllPtrFieldsNil tests whether all pointer fields in a struct are nil. This is useful when, for example, an API struct is handled by plugins which need to distinguish "no plugin accepted this spec" from "this spec is empty".

This function is only valid for structs and pointers to structs. Any other type will cause a panic. Passing a typed nil pointer will return true.

func Deref

func Deref[T any](ptr *T, def T) T

Deref dereferences ptr and returns the value it points to if no nil, or else returns def.

func Equal

func Equal[T comparable](a, b *T) bool

Equal returns true if both arguments are nil or both arguments dereference to the same value.

func To

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

To returns a pointer to the given value.

Types

This section is empty.

Jump to

Keyboard shortcuts

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