-
Notifications
You must be signed in to change notification settings - Fork 198
Expand file tree
/
Copy pathgenerics.go
More file actions
97 lines (84 loc) · 2.89 KB
/
generics.go
File metadata and controls
97 lines (84 loc) · 2.89 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package _generated
import "github.com/tinylib/msgp/msgp"
//go:generate msgp -v
type Int64 int
type GenericTest[T any, P msgp.RTFor[T]] struct {
A T
B P
C []T `msg:",allownil"`
D map[string]T `msg:",allownil"`
E GenericTest2[T, P, string]
F []GenericTest2[T, P, string] `msg:",allownil"`
G map[string]GenericTest2[T, P, string] `msg:",allownil"`
AP *T
CP []*T `msg:",allownil"`
DP map[string]*T `msg:",allownil"`
EP *GenericTest2[T, P, string]
FP []*GenericTest2[T, P, string] `msg:",allownil"`
GP map[string]*GenericTest2[T, P, string] `msg:",allownil"`
}
type GenericTest2[T any, P msgp.RTFor[T], B any] struct {
A T
}
//msgp:tuple GenericTuple
type GenericTuple[T any, P msgp.RTFor[T], B any] struct {
A T
B P
C []T `msg:",allownil"`
D map[string]T `msg:",allownil"`
E GenericTest2[T, P, string]
F []GenericTest2[T, P, string] `msg:",allownil"`
G map[string]GenericTest2[T, P, string] `msg:",allownil"`
AP *T
CP []*T `msg:",allownil"`
DP map[string]*T `msg:",allownil"`
EP *GenericTest2[T, P, string]
FP []*GenericTest2[T, P, string] `msg:",allownil"`
GP map[string]*GenericTest2[T, P, string] `msg:",allownil"`
}
// Type that doesn't have any fields using the generic type should just output valid code.
type GenericTestUnused[T any] struct {
A string
}
type GenericTestTwo[A, B any, AP msgp.RTFor[A], BP msgp.RTFor[B]] struct {
A A
B AP
C []A `msg:",allownil"`
D map[string]T `msg:",allownil"`
E GenericTest2[A, AP, string]
F []GenericTest2[A, AP, string] `msg:",allownil"`
G map[string]GenericTest2[A, AP, string] `msg:",allownil"`
AP *A
CP []*A `msg:",allownil"`
DP map[string]*A `msg:",allownil"`
EP *GenericTest2[A, AP, string]
FP []*GenericTest2[A, AP, string] `msg:",allownil"`
GP map[string]*GenericTest2[A, AP, string] `msg:",allownil"`
A2 B
B2 BP
C2 []B `msg:",allownil"`
D2 map[string]B `msg:",allownil"`
E2 GenericTest2[B, BP, string]
F2 []GenericTest2[B, BP, string] `msg:",allownil"`
G2 map[string]GenericTest2[B, BP, string] `msg:",allownil"`
AP2 *B
CP2 []*B `msg:",allownil"`
DP2 map[string]*B `msg:",allownil"`
EP2 *GenericTest2[B, BP, string]
FP2 []*GenericTest2[B, BP, string] `msg:",allownil"`
GP2 map[string]*GenericTest2[B, BP, string] `msg:",allownil"`
}
type GenericTest3List[A, B any, AP msgp.RTFor[A], BP msgp.RTFor[B]] []GenericTest3[A, B, AP, BP]
type GenericTest3Map[A, B any, AP msgp.RTFor[A], BP msgp.RTFor[B]] map[string]GenericTest3[A, B, AP, BP]
type GenericTest3Array[A, B any, AP msgp.RTFor[A], BP msgp.RTFor[B]] [5]GenericTest3[A, B, AP, BP]
type GenericTest3[A, B any, _ msgp.RTFor[A], _ msgp.RTFor[B]] struct {
A A
B B
}
// GenericTest4 has the msgp.RTFor constraint as a sub-constraint.
type GenericTest4[T any, P interface {
*T
msgp.RTFor[T]
}] struct {
Totals [60]T
}