ptr

package
v0.39.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package ptr provides generic and concrete helpers for working with pointers.

The generic functions To, From, and FromOr cover any type. Concrete helpers like String, Int, and Bool are provided for the most common stdlib types. Conversion helpers IntToStr and BoolToYesNo turn pointer values into human-readable strings.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(p *bool) bool

Bool dereferences a *bool, returning false when nil.

func BoolToYesNo

func BoolToYesNo(p *bool) string

BoolToYesNo converts a *bool to "Yes" or "No", returning "" when nil.

func From

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

From dereferences p, returning the zero value of T when p is nil.

func FromOr

func FromOr[T any](p *T, def T) T

FromOr dereferences p, returning def when p is nil.

func Int

func Int(p *int) int

Int dereferences a *int, returning 0 when nil.

func IntToStr

func IntToStr(p *int) string

IntToStr converts a *int to its string representation, returning "" when nil.

func String

func String(p *string) string

String dereferences a *string, returning "" when nil.

func To

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

To returns a pointer to v.

Types

This section is empty.

Jump to

Keyboard shortcuts

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