pointer

package
v0.166.2 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Deref

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

Deref will return the referenced value, or if the pointer has no value, then it returns with the zero value.

Example
package main

import (
	"github.com/adamluzsi/frameless/pkg/pointer"
)

type ExampleStruct struct {
	StrPtrField *string
	IntPtrField *int
}

func main() {
	var es ExampleStruct
	_ = pointer.Deref(es.StrPtrField)
	_ = pointer.Deref(es.IntPtrField)
}
Output:

func Of

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

Of takes the pointer of a value.

Example
package main

import (
	"github.com/adamluzsi/frameless/pkg/pointer"
)

type ExampleStruct struct {
	StrPtrField *string
	IntPtrField *int
}

func main() {
	_ = ExampleStruct{
		StrPtrField: pointer.Of("42"),
		IntPtrField: pointer.Of(42),
	}
}
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

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