1 /* 2 Copyright 2018 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 // Deprecated: Use functions in k8s.io/utils/ptr instead: ptr.To to obtain 18 // a pointer, ptr.Deref to dereference a pointer, ptr.Equal to compare 19 // dereferenced pointers. 20 package pointer 21 22 import ( 23 "time" 24 25 "k8s.io/utils/ptr" 26 ) 27 28 // AllPtrFieldsNil tests whether all pointer fields in a struct are nil. This is useful when, 29 // for example, an API struct is handled by plugins which need to distinguish 30 // "no plugin accepted this spec" from "this spec is empty". 31 // 32 // This function is only valid for structs and pointers to structs. Any other 33 // type will cause a panic. Passing a typed nil pointer will return true. 34 // 35 // Deprecated: Use ptr.AllPtrFieldsNil instead. 36 var AllPtrFieldsNil = ptr.AllPtrFieldsNil 37 38 // Int returns a pointer to an int. 39 var Int = ptr.To[int] 40 41 // IntPtr is a function variable referring to Int. 42 // 43 // Deprecated: Use ptr.To instead. 44 var IntPtr = Int // for back-compat 45 46 // IntDeref dereferences the int ptr and returns it if not nil, or else 47 // returns def. 48 var IntDeref = ptr.Deref[int] 49 50 // IntPtrDerefOr is a function variable referring to IntDeref. 51 // 52 // Deprecated: Use ptr.Deref instead. 53 var IntPtrDerefOr = IntDeref // for back-compat 54 55 // Int32 returns a pointer to an int32. 56 var Int32 = ptr.To[int32] 57 58 // Int32Ptr is a function variable referring to Int32. 59 // 60 // Deprecated: Use ptr.To instead. 61 var Int32Ptr = Int32 // for back-compat 62 63 // Int32Deref dereferences the int32 ptr and returns it if not nil, or else 64 // returns def. 65 var Int32Deref = ptr.Deref[int32] 66 67 // Int32PtrDerefOr is a function variable referring to Int32Deref. 68 // 69 // Deprecated: Use ptr.Deref instead. 70 var Int32PtrDerefOr = Int32Deref // for back-compat 71 72 // Int32Equal returns true if both arguments are nil or both arguments 73 // dereference to the same value. 74 var Int32Equal = ptr.Equal[int32] 75 76 // Uint returns a pointer to an uint 77 var Uint = ptr.To[uint] 78 79 // UintPtr is a function variable referring to Uint. 80 // 81 // Deprecated: Use ptr.To instead. 82 var UintPtr = Uint // for back-compat 83 84 // UintDeref dereferences the uint ptr and returns it if not nil, or else 85 // returns def. 86 var UintDeref = ptr.Deref[uint] 87 88 // UintPtrDerefOr is a function variable referring to UintDeref. 89 // 90 // Deprecated: Use ptr.Deref instead. 91 var UintPtrDerefOr = UintDeref // for back-compat 92 93 // Uint32 returns a pointer to an uint32. 94 var Uint32 = ptr.To[uint32] 95 96 // Uint32Ptr is a function variable referring to Uint32. 97 // 98 // Deprecated: Use ptr.To instead. 99 var Uint32Ptr = Uint32 // for back-compat 100 101 // Uint32Deref dereferences the uint32 ptr and returns it if not nil, or else 102 // returns def. 103 var Uint32Deref = ptr.Deref[uint32] 104 105 // Uint32PtrDerefOr is a function variable referring to Uint32Deref. 106 // 107 // Deprecated: Use ptr.Deref instead. 108 var Uint32PtrDerefOr = Uint32Deref // for back-compat 109 110 // Uint32Equal returns true if both arguments are nil or both arguments 111 // dereference to the same value. 112 var Uint32Equal = ptr.Equal[uint32] 113 114 // Int64 returns a pointer to an int64. 115 var Int64 = ptr.To[int64] 116 117 // Int64Ptr is a function variable referring to Int64. 118 // 119 // Deprecated: Use ptr.To instead. 120 var Int64Ptr = Int64 // for back-compat 121 122 // Int64Deref dereferences the int64 ptr and returns it if not nil, or else 123 // returns def. 124 var Int64Deref = ptr.Deref[int64] 125 126 // Int64PtrDerefOr is a function variable referring to Int64Deref. 127 // 128 // Deprecated: Use ptr.Deref instead. 129 var Int64PtrDerefOr = Int64Deref // for back-compat 130 131 // Int64Equal returns true if both arguments are nil or both arguments 132 // dereference to the same value. 133 var Int64Equal = ptr.Equal[int64] 134 135 // Uint64 returns a pointer to an uint64. 136 var Uint64 = ptr.To[uint64] 137 138 // Uint64Ptr is a function variable referring to Uint64. 139 // 140 // Deprecated: Use ptr.To instead. 141 var Uint64Ptr = Uint64 // for back-compat 142 143 // Uint64Deref dereferences the uint64 ptr and returns it if not nil, or else 144 // returns def. 145 var Uint64Deref = ptr.Deref[uint64] 146 147 // Uint64PtrDerefOr is a function variable referring to Uint64Deref. 148 // 149 // Deprecated: Use ptr.Deref instead. 150 var Uint64PtrDerefOr = Uint64Deref // for back-compat 151 152 // Uint64Equal returns true if both arguments are nil or both arguments 153 // dereference to the same value. 154 var Uint64Equal = ptr.Equal[uint64] 155 156 // Bool returns a pointer to a bool. 157 var Bool = ptr.To[bool] 158 159 // BoolPtr is a function variable referring to Bool. 160 // 161 // Deprecated: Use ptr.To instead. 162 var BoolPtr = Bool // for back-compat 163 164 // BoolDeref dereferences the bool ptr and returns it if not nil, or else 165 // returns def. 166 var BoolDeref = ptr.Deref[bool] 167 168 // BoolPtrDerefOr is a function variable referring to BoolDeref. 169 // 170 // Deprecated: Use ptr.Deref instead. 171 var BoolPtrDerefOr = BoolDeref // for back-compat 172 173 // BoolEqual returns true if both arguments are nil or both arguments 174 // dereference to the same value. 175 var BoolEqual = ptr.Equal[bool] 176 177 // String returns a pointer to a string. 178 var String = ptr.To[string] 179 180 // StringPtr is a function variable referring to String. 181 // 182 // Deprecated: Use ptr.To instead. 183 var StringPtr = String // for back-compat 184 185 // StringDeref dereferences the string ptr and returns it if not nil, or else 186 // returns def. 187 var StringDeref = ptr.Deref[string] 188 189 // StringPtrDerefOr is a function variable referring to StringDeref. 190 // 191 // Deprecated: Use ptr.Deref instead. 192 var StringPtrDerefOr = StringDeref // for back-compat 193 194 // StringEqual returns true if both arguments are nil or both arguments 195 // dereference to the same value. 196 var StringEqual = ptr.Equal[string] 197 198 // Float32 returns a pointer to a float32. 199 var Float32 = ptr.To[float32] 200 201 // Float32Ptr is a function variable referring to Float32. 202 // 203 // Deprecated: Use ptr.To instead. 204 var Float32Ptr = Float32 205 206 // Float32Deref dereferences the float32 ptr and returns it if not nil, or else 207 // returns def. 208 var Float32Deref = ptr.Deref[float32] 209 210 // Float32PtrDerefOr is a function variable referring to Float32Deref. 211 // 212 // Deprecated: Use ptr.Deref instead. 213 var Float32PtrDerefOr = Float32Deref // for back-compat 214 215 // Float32Equal returns true if both arguments are nil or both arguments 216 // dereference to the same value. 217 var Float32Equal = ptr.Equal[float32] 218 219 // Float64 returns a pointer to a float64. 220 var Float64 = ptr.To[float64] 221 222 // Float64Ptr is a function variable referring to Float64. 223 // 224 // Deprecated: Use ptr.To instead. 225 var Float64Ptr = Float64 226 227 // Float64Deref dereferences the float64 ptr and returns it if not nil, or else 228 // returns def. 229 var Float64Deref = ptr.Deref[float64] 230 231 // Float64PtrDerefOr is a function variable referring to Float64Deref. 232 // 233 // Deprecated: Use ptr.Deref instead. 234 var Float64PtrDerefOr = Float64Deref // for back-compat 235 236 // Float64Equal returns true if both arguments are nil or both arguments 237 // dereference to the same value. 238 var Float64Equal = ptr.Equal[float64] 239 240 // Duration returns a pointer to a time.Duration. 241 var Duration = ptr.To[time.Duration] 242 243 // DurationDeref dereferences the time.Duration ptr and returns it if not nil, or else 244 // returns def. 245 var DurationDeref = ptr.Deref[time.Duration] 246 247 // DurationEqual returns true if both arguments are nil or both arguments 248 // dereference to the same value. 249 var DurationEqual = ptr.Equal[time.Duration] 250