summaryrefslogtreecommitdiff
path: root/internal/util/ptr.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/util/ptr.go')
-rw-r--r--internal/util/ptr.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/internal/util/ptr.go b/internal/util/ptr.go
index 0ad207617..d7c30da85 100644
--- a/internal/util/ptr.go
+++ b/internal/util/ptr.go
@@ -34,6 +34,15 @@ func Ptr[T any](t T) *T {
return &t
}
+// PtrIf returns ptr value only if 't' non-zero.
+func PtrIf[T comparable](t T) *T {
+ var z T
+ if t == z {
+ return nil
+ }
+ return &t
+}
+
// PtrValueOr returns either value of ptr, or default.
func PtrValueOr[T any](t *T, _default T) T {
if t != nil {