ptr

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: Apache-2.0 Imports: 0 Imported by: 24

Documentation

Overview

Package ptr provides generic utility functions for operating on/creating pointers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func From added in v1.1.0

func From[V any](v *V) V

From dereferences the given pointer or returns the default value if <nil>, this mimics lots of the utility functions in the AWS SDK which do the same thing but were written before generics.

func SetIfNil

func SetIfNil[V any](p **V, otherP *V)

SetIfNil sets the first pointer to the other given pointer if first pointer is nil.

NOTE: This is a simple convenience function meant to replace the

if x == nil {
    x = y
}

code construction which takes 3 lines whilst calling this function takes one.

func To

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

To returns a pointer to a copy of the provided object.

NOTE: This is required for getting a pointer to a value that is defined as a Go constant (not the constant itself, passing it to a function will create a variable copy with the same value). For variables the pointer can be acquired directly using the & operator so there is no point in using this function in that case.

Types

This section is empty.

Jump to

Keyboard shortcuts

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