pointer

package
v2.2.3 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2023 License: MIT Imports: 1 Imported by: 9

Documentation

Overview

Package pointer contains some util functions to operate go pointer.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractPointer

func ExtractPointer(value any) any

ExtractPointer returns the underlying value by the given interface type Play: https://go.dev/play/p/D7HFjeWU2ZP

Example
a := 1
b := &a
c := &b
d := &c

result := ExtractPointer(d)

fmt.Println(result)
Output:

1

func Of added in v2.2.2

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

Of returns a pointer to the value `v`. Play: https://go.dev/play/p/HFd70x4DrMj

Example
result1 := Of(123)
result2 := Of("abc")

fmt.Println(*result1)
fmt.Println(*result2)
Output:

123
abc

func Unwrap added in v2.2.2

func Unwrap[T any](p *T) T

Unwrap returns the value from the pointer. Play: https://go.dev/play/p/cgeu3g7cjWb

Example
a := 123
b := "abc"

result1 := Unwrap(&a)
result2 := Unwrap(&b)

fmt.Println(result1)
fmt.Println(result2)
Output:

123
abc

Types

This section is empty.

Jump to

Keyboard shortcuts

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