Skip to content

Commit ae3349e

Browse files
committed
Deprecate package for Go 1.26+ (new(expr) replaces helpers)
The end of yet another short story...
1 parent b187755 commit ae3349e

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

.github/workflows/go.yml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,7 @@ jobs:
1515
matrix:
1616
os: [ubuntu-latest]
1717
go:
18-
- "1.11"
19-
- "1.12"
20-
- "1.13"
21-
- "1.14"
22-
- "1.15"
23-
- "1.16"
24-
- "1.17"
25-
- "1.18"
26-
- "1.19"
27-
- "1.20"
28-
- "1.21"
29-
- "1.22"
18+
- ">=1.26.0-rc.1"
3019
steps:
3120
- uses: actions/checkout@v6
3221
- name: Set up Go:${{ matrix.go }}
@@ -46,7 +35,7 @@ jobs:
4635
- name: Set up Go
4736
uses: actions/setup-go@v6
4837
with:
49-
go-version: "1.21"
38+
go-version: ">=1.26.0-rc.1"
5039
- name: Make check
5140
run: make check
5241
- uses: codecov/codecov-action@v5

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
Package pointer contains helper routines for simplifying the creation
99
of optional fields of basic type.
1010

11+
## Deprecated in Go 1.26+
12+
13+
Starting with **Go 1.26**, the built-in `new` function supports expressions:
14+
`p := new(42)` or `&Age: new(calculateAge())`.
15+
16+
This replaces all helpers like `pointer.Of[Value](v)` or type-specific `pointer.Int(1)`.
17+
**No need to use this package anymore — copy the generics version locally only if stuck on Go 1.18–1.25.**
18+
1119
## A little copying is better than a little dependency
1220

1321
With the advent of generics in go 1.18, using this library in your code is

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Deprecated: Use built-in `new(expr)` in Go 1.26+ instead of pointer helpers.
2+
// See https://tip.golang.org/doc/go1.26#language
13
module github.com/xorcare/pointer
24

3-
go 1.18
5+
go 1.26

pointer_118.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build go1.18
6-
// +build go1.18
5+
//go:build go1.18 && !go1.26
76

87
package pointer
98

pointer_126.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright © 2022 Vasiliy Vasilyuk. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// Deprecated: Use built-in `new(expr)` in Go 1.26+.
6+
// Only for Go 1.18–1.25.
7+
//go:build go1.26
8+
9+
package pointer
10+
11+
// Of is a helper routine that allocates a new any value
12+
// to store v and returns a pointer to it.
13+
func Of[Value any](v Value) *Value {
14+
return new(v)
15+
}

0 commit comments

Comments
 (0)