pointer

package
v0.0.63 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2025 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pointer

func Pointer[T any](t T) *T

Pointer returns a pointer to the provided value of type T. It's useful in situations where you need a pointer to a value, particularly when dealing with literals or temporary values.

Example usage: intPtr := Pointer(42) strPtr := Pointer("hello")

func Value

func Value[T any](ptr *T) T

Value returns the value pointed to by the given pointer of type T. If the pointer is nil, it returns the zero value of type T. It's useful for safely dereferencing pointers, especially when dealing with potentially nil pointers.

Example usage: intPtr := Pointer(42) intValue := Value(intPtr) // intValue == 42

var nilPtr *string strValue := Value(nilPtr) // strValue == "" (zero value for string)

Types

This section is empty.

Jump to

Keyboard shortcuts

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