Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,7 @@ jobs:
matrix:
os: [ubuntu-latest]
go:
- "1.11"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait for release 1.26 is published

- "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 }}
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions pointer_118.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 15 additions & 0 deletions pointer_126.go
Original file line number Diff line number Diff line change
@@ -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)
}