Skip to content

Commit 5c92164

Browse files
committed
utils: add generic function for pointers
Go doesn't offer a generic method to convert a type in to its pointer. This method is practical for the podman bindings where there are several field which are pointer, and without this method, you would need to define a variable and then pass its address. E.g for booleans: foo := utils.Ptr(true) instead of t := true foo := &t Signed-off-by: Alice Frosi <[email protected]>
1 parent cace937 commit 5c92164

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

pkg/utils/pointer.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package utils
2+
3+
func Ptr[T any](v T) *T {
4+
return &v
5+
}

0 commit comments

Comments
 (0)