aboutsummaryrefslogtreecommitdiffstats
path: root/library/go/ptr/ptr.go
blob: 7ebf3dbd727c923609819b638abe7fb786c4d057 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package ptr

import "time"

// Int returns pointer to provided value
func Int(v int) *int { return &v }

// Int8 returns pointer to provided value
func Int8(v int8) *int8 { return &v }

// Int16 returns pointer to provided value
func Int16(v int16) *int16 { return &v }

// Int32 returns pointer to provided value
func Int32(v int32) *int32 { return &v }

// Int64 returns pointer to provided value
func Int64(v int64) *int64 { return &v }

// Uint returns pointer to provided value
func Uint(v uint) *uint { return &v }

// Uint8 returns pointer to provided value
func Uint8(v uint8) *uint8 { return &v }

// Uint16 returns pointer to provided value
func Uint16(v uint16) *uint16 { return &v }

// Uint32 returns pointer to provided value
func Uint32(v uint32) *uint32 { return &v }

// Uint64 returns pointer to provided value
func Uint64(v uint64) *uint64 { return &v }

// Float32 returns pointer to provided value
func Float32(v float32) *float32 { return &v }

// Float64 returns pointer to provided value
func Float64(v float64) *float64 { return &v }

// Bool returns pointer to provided value
func Bool(v bool) *bool { return &v }

// String returns pointer to provided value
func String(v string) *string { return &v }

// Byte returns pointer to provided value
func Byte(v byte) *byte { return &v }

// Rune returns pointer to provided value
func Rune(v rune) *rune { return &v }

// Complex64 returns pointer to provided value
func Complex64(v complex64) *complex64 { return &v }

// Complex128 returns pointer to provided value
func Complex128(v complex128) *complex128 { return &v }

// Time returns pointer to provided value
func Time(v time.Time) *time.Time { return &v }

// Duration returns pointer to provided value
func Duration(v time.Duration) *time.Duration { return &v }

// T returns pointer to provided value
func T[T any](v T) *T { return &v }

// From returns value from pointer
func From[T any](v *T) T {
	if v == nil {
		return *new(T)
	}

	return *v
}