-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathptr.go
94 lines (72 loc) · 1.18 KB
/
ptr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
Package ptr provides utility functions for converting non-addressable primitive types to pointers.
Its useful in contexts where a variable gives nil primitive type pointers semantics
(often meaning "not set") which can make it annoying to set the value.
Example
type Foo struct {
A *int
}
func main() {
foo := Foo{
A: ptr.Int(1)
}
}
*/
package ptr
func Int(v int) *int {
return &v
}
func Int8(v int8) *int8 {
return &v
}
func Int16(v int16) *int16 {
return &v
}
func Int32(v int32) *int32 {
return &v
}
func Int64(v int64) *int64 {
return &v
}
func Uint(v uint) *uint {
return &v
}
func Uint8(v uint8) *uint8 {
return &v
}
func Uint16(v uint16) *uint16 {
return &v
}
func Uint32(v uint32) *uint32 {
return &v
}
func Uint64(v uint64) *uint64 {
return &v
}
func Float32(v float32) *float32 {
return &v
}
func Float64(v float64) *float64 {
return &v
}
func String(v string) *string {
return &v
}
func Bool(v bool) *bool {
return &v
}
func Byte(v byte) *byte {
return &v
}
func Rune(v rune) *rune {
return &v
}
func Complex64(v complex64) *complex64 {
return &v
}
func Complex128(v complex128) *complex128 {
return &v
}
func To[T any](v T) *T {
return &v
}