-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrapped.go
67 lines (54 loc) · 1.04 KB
/
wrapped.go
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
// Content managed by Project Forge, see [projectforge.md] for details.
package types
type Wrapped struct {
K string `json:"k"`
T Type `json:"t,omitempty"`
}
var _ Type = (*Wrapped)(nil)
func Wrap(t Type) *Wrapped {
w, ok := t.(*Wrapped)
if ok {
return w
}
return &Wrapped{K: t.Key(), T: t}
}
func (x *Wrapped) Key() string {
return x.K
}
func (x *Wrapped) Sortable() bool {
return x.T.Sortable()
}
func (x *Wrapped) Scalar() bool {
return x.T.Scalar()
}
func (x *Wrapped) String() string {
return x.T.String()
}
func (x *Wrapped) From(v any) any {
return x.T.From(v)
}
func (x *Wrapped) Default(key string) any {
return x.T.Default(key)
}
func (x *Wrapped) Equals(tgt *Wrapped) bool {
return x.String() == tgt.String()
}
func (x *Wrapped) IsOption() bool {
_, ok := x.T.(*Option)
return ok
}
func (x *Wrapped) EnumKey() string {
e, ok := x.T.(*Enum)
if !ok {
return ""
}
return e.Ref
}
func (x *Wrapped) IsListOf(tgt *Wrapped) bool {
switch t := x.T.(type) {
case *List:
return t.V.Equals(tgt)
default:
return false
}
}