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 Init ¶ added in v0.137.0
func Init[T any, IV initialiser[T]](v **T, init IV) *T
Init will initialise a variable **T by first checking its value, and if it's not set, it assigns a default value to it. Init is safe to use concurrently, it has no race condition.
Example ¶
package main import ( "github.com/adamluzsi/frameless/pkg/pointer" ) func main() { type MyType struct { V *string } var mt MyType _ = pointer.Init(&mt.V, func() string { return "default value from a lambda" }) _ = pointer.Init(&mt.V, pointer.Of("default value from a pointer")) }
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.
Click to show internal directories.
Click to hide internal directories.