Skip to content

Commit 8d72bd0

Browse files
committed
Pointer: Add generic Pointer func
This adds a new, generic pointer func to the pointer package.
1 parent 3a6ce19 commit 8d72bd0

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module k8s.io/utils
22

3-
go 1.12
3+
go 1.18
44

55
require (
66
github.com/davecgh/go-spew v1.1.1

pointer/generic.go

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

pointer/generic_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package pointer
2+
3+
import "testing"
4+
5+
func TestPointer(t *testing.T) {
6+
ptr := Pointer(5)
7+
if *ptr != 5 {
8+
t.Errorf("expected pointer value to be 5, was %v", *ptr)
9+
}
10+
}

0 commit comments

Comments
 (0)