Skip to content

Commit 974a39b

Browse files
committed
Update docs
1 parent a285f58 commit 974a39b

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
# pointer
2-
[![GoDoc](https://godoc.org/github.com/AlekSi/pointer?status.svg)](https://godoc.org/github.com/AlekSi/pointer)
3-
[![Build Status](https://travis-ci.org/AlekSi/pointer.svg)](https://travis-ci.org/AlekSi/pointer)
42

5-
Go package pointer provides helpers to get pointers to values of built-in types.
3+
[![Go Reference](https://pkg.go.dev/badge/github.com/AlekSi/pointer.svg)](https://pkg.go.dev/github.com/AlekSi/pointer)
4+
5+
Go package `pointer` provides helpers to convert between pointers and values of built-in
6+
(and, with Go 1.18+ generics, of any) types.
67

78
```
89
go get github.com/AlekSi/pointer
910
```
1011

11-
API is stable. [Documentation](http://godoc.org/github.com/AlekSi/pointer).
12+
API is stable. [Documentation](https://pkg.go.dev/github.com/AlekSi/pointer).
1213

1314
```go
1415
package motivationalexample

generic.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33

44
package pointer
55

6+
// To returns a pointer to the passed value.
67
func To[T any](t T) *T {
78
return &t
89
}
910

11+
// ToOrNil returns a pointer to the passed value, or nil, if the passed value is a zero value.
12+
// If the passed value has `IsZero() bool` method (for example, time.Time instance),
13+
// it is used to determine if the value is zero.
1014
func ToOrNil[T comparable](t T) *T {
1115
if z, ok := any(t).(interface{ IsZero() bool }); ok {
1216
if z.IsZero() {
@@ -22,6 +26,7 @@ func ToOrNil[T comparable](t T) *T {
2226
return &t
2327
}
2428

29+
// Get returns the value from the passed pointer or the zero value if the pointer is nil.
2530
func Get[T any](t *T) T {
2631
if t == nil {
2732
var zero T

pointer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Package pointer provides helpers to get pointers to values of built-in types.
1+
// Package pointer provides helpers to convert between pointers and values of built-in (and, with generics, of any) types.
22
package pointer // import "github.com/AlekSi/pointer"
33

44
import (

0 commit comments

Comments
 (0)