summaryrefslogtreecommitdiff
path: root/vendor/github.com/modern-go/reflect2/safe_type.go
blob: ee4e7bb6edfdd031eb6fc2c06a7550e249a6d0b7 (plain)
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
package reflect2

import (
	"reflect"
	"unsafe"
)

type safeType struct {
	reflect.Type
	cfg *frozenConfig
}

func (type2 *safeType) New() interface{} {
	return reflect.New(type2.Type).Interface()
}

func (type2 *safeType) UnsafeNew() unsafe.Pointer {
	panic("does not support unsafe operation")
}

func (type2 *safeType) Elem() Type {
	return type2.cfg.Type2(type2.Type.Elem())
}

func (type2 *safeType) Type1() reflect.Type {
	return type2.Type
}

func (type2 *safeType) PackEFace(ptr unsafe.Pointer) interface{} {
	panic("does not support unsafe operation")
}

func (type2 *safeType) Implements(thatType Type) bool {
	return type2.Type.Implements(thatType.Type1())
}

func (type2 *safeType) RType() uintptr {
	panic("does not support unsafe operation")
}

func (type2 *safeType) Indirect(obj interface{}) interface{} {
	return reflect.Indirect(reflect.ValueOf(obj)).Interface()
}

func (type2 *safeType) UnsafeIndirect(ptr unsafe.Pointer) interface{} {
	panic("does not support unsafe operation")
}

func (type2 *safeType) LikePtr() bool {
	panic("does not support unsafe operation")
}

func (type2 *safeType) IsNullable() bool {
	return IsNullable(type2.Kind())
}

func (type2 *safeType) IsNil(obj interface{}) bool {
	if obj == nil {
		return true
	}
	return reflect.ValueOf(obj).Elem().IsNil()
}

func (type2 *safeType) UnsafeIsNil(ptr unsafe.Pointer) bool {
	panic("does not support unsafe operation")
}

func (type2 *safeType) Set(obj interface{}, val interface{}) {
	reflect.ValueOf(obj).Elem().Set(reflect.ValueOf(val).Elem())
}

func (type2 *safeType) UnsafeSet(ptr unsafe.Pointer, val unsafe.Pointer) {
	panic("does not support unsafe operation")
}

func (type2 *safeType) AssignableTo(anotherType Type) bool {
	return type2.Type1().AssignableTo(anotherType.Type1())
}