-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathpointerx.go
More file actions
120 lines (104 loc) · 2.11 KB
/
pointerx.go
File metadata and controls
120 lines (104 loc) · 2.11 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package pointerx
// Ptr returns the input value's pointer.
func Ptr[T any](v T) *T {
return &v
}
// Deref returns the input values de-referenced value, or zero value if nil.
func Deref[T any](p *T) T {
if p == nil {
var zero T
return zero
}
return *p
}
// String returns the input value's pointer.
// Deprecated: use Ptr instead.
func String(s string) *string {
return &s
}
// StringR is the reverse to String.
// Deprecated: use Deref instead.
func StringR(s *string) string {
if s == nil {
return ""
}
return *s
}
// Int returns the input value's pointer.
// Deprecated: use Ptr instead.
func Int(s int) *int {
return &s
}
// IntR is the reverse to Int.
// Deprecated: use Deref instead.
func IntR(s *int) int {
if s == nil {
return int(0)
}
return *s
}
// Int32 returns the input value's pointer.
// Deprecated: use Ptr instead.
func Int32[T any](s int32) *int32 {
return &s
}
// Int32R is the reverse to Int32.
// Deprecated: use Deref instead.
func Int32R(s *int32) int32 {
if s == nil {
return int32(0)
}
return *s
}
// Int64 returns the input value's pointer.
// Deprecated: use Ptr instead.
func Int64(s int64) *int64 {
return &s
}
// Int64R is the reverse to Int64.
// Deprecated: use Deref instead.
func Int64R(s *int64) int64 {
if s == nil {
return int64(0)
}
return *s
}
// Float32 returns the input value's pointer.
// Deprecated: use Ptr instead.
func Float32(s float32) *float32 {
return &s
}
// Float32R is the reverse to Float32.
// Deprecated: use Deref instead.
func Float32R(s *float32) float32 {
if s == nil {
return float32(0)
}
return *s
}
// Float64 returns the input value's pointer.
// Deprecated: use Ptr instead.
func Float64(s float64) *float64 {
return &s
}
// Float64R is the reverse to Float64.
// Deprecated: use Deref instead.
func Float64R(s *float64) float64 {
if s == nil {
return float64(0)
}
return *s
}
// Bool returns the input value's pointer.
// Deprecated: use Ptr instead.
func Bool(s bool) *bool {
return &s
}
// BoolR is the reverse to Bool.
// Deprecated: use Deref instead.
func BoolR(s *bool) bool {
if s == nil {
return false
}
return *s
}