diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index b261414..9f7eab9 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -15,18 +15,7 @@ jobs: matrix: os: [ubuntu-latest] go: - - "1.11" - - "1.12" - - "1.13" - - "1.14" - - "1.15" - - "1.16" - - "1.17" - - "1.18" - - "1.19" - - "1.20" - - "1.21" - - "1.22" + - ">=1.26.0-rc.2" steps: - uses: actions/checkout@v6 - name: Set up Go:${{ matrix.go }} @@ -46,7 +35,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v6 with: - go-version: "1.21" + go-version: ">=1.26.0-rc.2" - name: Make check run: make check - uses: codecov/codecov-action@v5 diff --git a/README.md b/README.md index 0663825..6f191b5 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,14 @@ Package pointer contains helper routines for simplifying the creation of optional fields of basic type. +## Deprecated in Go 1.26+ + +Starting with **Go 1.26**, the built-in `new` function supports expressions: +`p := new(42)` or `&Age: new(calculateAge())`. + +This replaces all helpers like `pointer.Of[Value](v)` or type-specific `pointer.Int(1)`. +**No need to use this package anymore — copy the generics version locally only if stuck on Go 1.18–1.25.** + ## A little copying is better than a little dependency With the advent of generics in go 1.18, using this library in your code is diff --git a/go.mod b/go.mod index 2d625f0..bea0717 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ +// Deprecated: Use built-in `new(expr)` in Go 1.26+ instead of pointer helpers. +// See https://tip.golang.org/doc/go1.26#language module github.com/xorcare/pointer -go 1.18 +go 1.26 diff --git a/pointer_118.go b/pointer_118.go index 42fe8c5..318f7a4 100644 --- a/pointer_118.go +++ b/pointer_118.go @@ -2,8 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build go1.18 -// +build go1.18 +//go:build go1.18 && !go1.26 package pointer diff --git a/pointer_126.go b/pointer_126.go new file mode 100644 index 0000000..90ca9ac --- /dev/null +++ b/pointer_126.go @@ -0,0 +1,15 @@ +// Copyright © 2022 Vasiliy Vasilyuk. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Deprecated: Use built-in `new(expr)` in Go 1.26+. +// Only for Go 1.18–1.25. +//go:build go1.26 + +package pointer + +// Of is a helper routine that allocates a new any value +// to store v and returns a pointer to it. +func Of[Value any](v Value) *Value { + return new(v) +}