-
Notifications
You must be signed in to change notification settings - Fork 0
/
call_result.go
59 lines (54 loc) · 1.1 KB
/
call_result.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
package dscope
import (
"reflect"
"github.com/reusee/e5"
)
type CallResult struct {
positionsByType map[reflect.Type]int
Values []reflect.Value
}
func (c CallResult) Extract(targets ...any) {
for i, target := range targets {
if target == nil {
continue
}
targetValue := reflect.ValueOf(target)
if targetValue.Kind() != reflect.Ptr {
panic(we.With(
e5.Info("%T is not a pointer", target),
)(
ErrBadArgument,
))
}
if targetValue.Type().Elem() != c.Values[i].Type() {
panic(we.With(
e5.Info("%T is not a pointer to %v",
target,
targetValue.Type().Elem()),
)(
ErrBadArgument,
))
}
targetValue.Elem().Set(c.Values[i])
}
}
func (c CallResult) Assign(targets ...any) {
for _, target := range targets {
if target == nil {
continue
}
targetValue := reflect.ValueOf(target)
if targetValue.Kind() != reflect.Ptr {
panic(we.With(
e5.Info("%v is not a pointer", target),
)(
ErrBadArgument,
))
}
pos, ok := c.positionsByType[targetValue.Type().Elem()]
if !ok {
continue
}
targetValue.Elem().Set(c.Values[pos])
}
}