gptr

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2023 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Of

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

Of returns a pointer that points to equivalent value of value v. (T → *T). It is useful when you want to "convert" a unaddressable value to pointer.

If you need to assign the address of a literal to a pointer:

 payload := struct {
	    Name *string
 }

The practice without generic:

x := "name"
payload.Name = &x

Use generic:

payload.Name = Of("name")

💡 HINT: use [Indirect] to dereference pointer (*T → T).

⚠️ WARNING: The returned pointer does not point to the original value because Go is always pass by value, user CAN NOT modify the value by modifying the pointer.

Types

This section is empty.

Jump to

Keyboard shortcuts

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