diff --git a/ptr/ptr.go b/ptr/ptr.go index ea847fd3..0388eb21 100644 --- a/ptr/ptr.go +++ b/ptr/ptr.go @@ -46,11 +46,6 @@ func AllPtrFieldsNil(obj interface{}) bool { return true } -// To returns a pointer to the given value. -func To[T any](v T) *T { - return &v -} - // Deref dereferences ptr and returns the value it points to if not nil, or else // returns def. func Deref[T any](ptr *T, def T) T { diff --git a/ptr/ptr_go125.go b/ptr/ptr_go125.go new file mode 100644 index 00000000..e98243ed --- /dev/null +++ b/ptr/ptr_go125.go @@ -0,0 +1,24 @@ +//go:build !go1.26 + +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package ptr + +// To returns a pointer to the given value. +func To[T any](v T) *T { + return &v +} diff --git a/ptr/ptr_go126.go b/ptr/ptr_go126.go new file mode 100644 index 00000000..26d5eddb --- /dev/null +++ b/ptr/ptr_go126.go @@ -0,0 +1,27 @@ +//go:build go1.26 + +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package ptr + +// To returns a pointer to the given value. +// Deprecated: Use new(T) instead. +// +//go:fix inline +func To[T any](v T) *T { + return new(v) +}