ptr

package module
v0.0.0-...-489e694 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: MIT Imports: 1 Imported by: 7

README

go-ptr

A collection of utility functions to work with pointers, commonly used for optional values.

Go Reference

Installation

go get -u github.com/cidverse/go-ptr

Usage

generics

fmt.Printf("%#v\n", ptr.Ptr("hello world"))

Primitives

fmt.Printf("%#v\n", ptr.String("hello world"))
fmt.Printf("%#v\n", ptr.Int("hello world"))

License

Released under the MIT license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(b bool) *bool

func Duration

func Duration(d time.Duration) *time.Duration

func False

func False() *bool

func Float32

func Float32(f float32) *float32

func Float64

func Float64(f float64) *float64

func Int

func Int(i int) *int

func Int32

func Int32(i int32) *int32

func Int64

func Int64(i int64) *int64

func Int64ToInt

func Int64ToInt(i *int64) *int

func IntToInt64

func IntToInt64(i *int) *int64

func Ptr

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

Ptr returns a new pointer to the given value.

func Rune

func Rune(r rune) *rune

func String

func String(s string) *string

func Time

func Time(t time.Time) *time.Time

func True

func True() *bool

func Uint8

func Uint8(u uint8) *uint8

func Uint16

func Uint16(u uint16) *uint16

func Uint32

func Uint32(u uint32) *uint32

func Uint64

func Uint64(u uint64) *uint64

func Value

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

Value returns a value behind the pointer or the zero value when the pointer is nil.

func ValueOrDefault

func ValueOrDefault[T any](p *T, defaultValue T) T

ValueOrDefault returns a value behind the pointer or the default value when the pointer is nil.

Types

This section is empty.

Jump to

Keyboard shortcuts

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