Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Copy ¶
func Copy[T any](in *T) *T
Copy copies value behind the pointer and returns a new pointer to the copy.
func To ¶
func To[T any](t T) *T
To returns a pointer to value.
This function is very useful for single-line expressions, where "&" cannot be used:
in := struct {
OptionalField *string
}{
OptionalField: ptr.To("works fine"),
}
To always create a pointer to copy of the value:
value := "v1" in.OptionalField = ptr.To(value) value = "v2" // in.OptionalField is not changed
func Value ¶
func Value[T any](ptr *T) T
Value returns a value behind the pointer or zero value when value is nil.
func ValueOrDefault ¶
func ValueOrDefault[T any](ptr *T, defaultValue T) T
ValueOrDefault returns a value behind the pointer or defaultValue when value is nil.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.