pointer.go 7.5 KB

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