@@ -3,57 +3,147 @@ package u
3
3
// Bool is a `bool` that can be unset
4
4
type Bool = Var [bool ]
5
5
6
+ // NewBool creates a new Bool with the given value
7
+ func NewBool (val bool ) Bool {
8
+ return NewVar (val )
9
+ }
10
+
6
11
// String is a `string` that can be unset
7
12
type String = Var [string ]
8
13
14
+ // NewString creates a new String with the given value
15
+ func NewString (val string ) String {
16
+ return NewVar (val )
17
+ }
18
+
9
19
// Float64 is a `float64` that can be unset
10
20
type Float64 = Var [float64 ]
11
21
22
+ // NewFloat64 creates a new Float64 with the given value
23
+ func NewFloat64 (val float64 ) Float64 {
24
+ return NewVar (val )
25
+ }
26
+
12
27
// Float32 is a `float32` that can be unset
13
28
type Float32 = Var [float32 ]
14
29
30
+ // NewFloat32 creates a new Float32 with the given value
31
+ func NewFloat32 (val float32 ) Float32 {
32
+ return NewVar (val )
33
+ }
34
+
15
35
// Uint is a `uint` that can be unset
16
36
type Uint = Var [uint ]
17
37
38
+ // NewUint creates a new Uint with the given value
39
+ func NewUint (val uint ) Uint {
40
+ return NewVar (val )
41
+ }
42
+
18
43
// Uint8 is a `uint8` that can be unset
19
44
type Uint8 = Var [uint8 ]
20
45
46
+ // NewUint8 creates a new Uint8 with the given value
47
+ func NewUint8 (val uint8 ) Uint8 {
48
+ return NewVar (val )
49
+ }
50
+
21
51
// Uint16 is a `uint16` that can be unset
22
52
type Uint16 = Var [uint16 ]
23
53
54
+ // NewUint16 creates a new Uint16 with the given value
55
+ func NewUint16 (val uint16 ) Uint16 {
56
+ return NewVar (val )
57
+ }
58
+
24
59
// Uint32 is a `uint32` that can be unset
25
60
type Uint32 = Var [uint32 ]
26
61
62
+ // NewUint32 creates a new Uint32 with the given value
63
+ func NewUint32 (val uint32 ) Uint32 {
64
+ return NewVar (val )
65
+ }
66
+
27
67
// Uint64 is a `uint64` that can be unset
28
68
type Uint64 = Var [uint64 ]
29
69
70
+ // NewUint64 creates a new Uint64 with the given value
71
+ func NewUint64 (val uint64 ) Uint64 {
72
+ return NewVar (val )
73
+ }
74
+
30
75
// Byte is a `byte` that can be unset
31
76
type Byte = Var [byte ]
32
77
78
+ // NewByte creates a new Byte with the given value
79
+ func NewByte (val byte ) Byte {
80
+ return NewVar (val )
81
+ }
82
+
33
83
// Rune is a `rune` that can be unset
34
84
type Rune = Var [rune ]
35
85
86
+ // NewRune creates a new Rune with the given value
87
+ func NewRune (val rune ) Rune {
88
+ return NewVar (val )
89
+ }
90
+
36
91
// Complex64 is a `complex64` that can be unset
37
92
type Complex64 = Var [complex64 ]
38
93
94
+ // NewComplex64 creates a new Complex64 with the given value
95
+ func NewComplex64 (val complex64 ) Complex64 {
96
+ return NewVar (val )
97
+ }
98
+
39
99
// Complex128 is a `complex128` that can be unset
40
100
type Complex128 = Var [complex128 ]
41
101
102
+ // NewComplex128 creates a new Complex128 with the given value
103
+ func NewComplex128 (val complex128 ) Complex128 {
104
+ return NewVar (val )
105
+ }
106
+
42
107
// Int is an `int` that can be unset
43
108
type Int = Var [int ]
44
109
110
+ // NewInt creates a new Int with the given value
111
+ func NewInt (val int ) Int {
112
+ return NewVar (val )
113
+ }
114
+
45
115
// Int8 is an `int8` that can be unset
46
116
type Int8 = Var [int8 ]
47
117
118
+ // NewInt8 creates a new Int8 with the given value
119
+ func NewInt8 (val int8 ) Int8 {
120
+ return NewVar (val )
121
+ }
122
+
48
123
// Int16 is an `int16` that can be unset
49
124
type Int16 = Var [int16 ]
50
125
126
+ // NewInt16 creates a new Int16 with the given value
127
+ func NewInt16 (val int16 ) Int16 {
128
+ return NewVar (val )
129
+ }
130
+
51
131
// Int32 is an `int32` that can be unset
52
132
type Int32 = Var [int32 ]
53
133
134
+ // NewInt32 creates a new Int32 with the given value
135
+ func NewInt32 (val int32 ) Int32 {
136
+ return NewVar (val )
137
+ }
138
+
54
139
// Int64 is an `int64` that can be unset
55
140
type Int64 = Var [int64 ]
56
141
142
+ // NewInt64 creates a new Int64 with the given value
143
+ func NewInt64 (val int64 ) Int64 {
144
+ return NewVar (val )
145
+ }
146
+
57
147
// Var is a variable that can be set, unset and queried for its state.
58
148
type Var [T any ] struct {
59
149
val T
@@ -83,3 +173,8 @@ func (v *Var[T]) Unset() {
83
173
var temp T
84
174
v .val = temp
85
175
}
176
+
177
+ // NewVar creates a new Var with the given value
178
+ func NewVar [T any ](val T ) Var [T ] {
179
+ return Var [T ]{val : val , set : true }
180
+ }
0 commit comments