Files
pocket-id-pocket-id/backend/internal/utils/ptr_util.go
2025-10-03 11:24:53 +02:00

17 lines
299 B
Go

package utils
// Ptr returns a pointer to the given value.
func Ptr[T any](v T) *T {
return &v
}
// PtrOrNil returns a pointer to v if v is not the zero value of its type,
// otherwise it returns nil.
func PtrOrNil[T comparable](v T) *T {
var zero T
if v == zero {
return nil
}
return &v
}