diff options
author | Rutger Broekhoff | 2023-12-29 21:31:53 +0100 |
---|---|---|
committer | Rutger Broekhoff | 2023-12-29 21:31:53 +0100 |
commit | 404aeae4545d2426c089a5f8d5e82dae56f5212b (patch) | |
tree | 2d84e00af272b39fc04f3795ae06bc48970e57b5 /vendor/github.com/modern-go/reflect2/safe_field.go | |
parent | 209d8b0187ed025dec9ac149ebcced3462877bff (diff) | |
download | gitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.tar.gz gitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.zip |
Make Nix builds work
Diffstat (limited to 'vendor/github.com/modern-go/reflect2/safe_field.go')
-rw-r--r-- | vendor/github.com/modern-go/reflect2/safe_field.go | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/vendor/github.com/modern-go/reflect2/safe_field.go b/vendor/github.com/modern-go/reflect2/safe_field.go new file mode 100644 index 0000000..d4ba1f4 --- /dev/null +++ b/vendor/github.com/modern-go/reflect2/safe_field.go | |||
@@ -0,0 +1,58 @@ | |||
1 | package reflect2 | ||
2 | |||
3 | import ( | ||
4 | "reflect" | ||
5 | "unsafe" | ||
6 | ) | ||
7 | |||
8 | type safeField struct { | ||
9 | reflect.StructField | ||
10 | } | ||
11 | |||
12 | func (field *safeField) Offset() uintptr { | ||
13 | return field.StructField.Offset | ||
14 | } | ||
15 | |||
16 | func (field *safeField) Name() string { | ||
17 | return field.StructField.Name | ||
18 | } | ||
19 | |||
20 | func (field *safeField) PkgPath() string { | ||
21 | return field.StructField.PkgPath | ||
22 | } | ||
23 | |||
24 | func (field *safeField) Type() Type { | ||
25 | panic("not implemented") | ||
26 | } | ||
27 | |||
28 | func (field *safeField) Tag() reflect.StructTag { | ||
29 | return field.StructField.Tag | ||
30 | } | ||
31 | |||
32 | func (field *safeField) Index() []int { | ||
33 | return field.StructField.Index | ||
34 | } | ||
35 | |||
36 | func (field *safeField) Anonymous() bool { | ||
37 | return field.StructField.Anonymous | ||
38 | } | ||
39 | |||
40 | func (field *safeField) Set(obj interface{}, value interface{}) { | ||
41 | val := reflect.ValueOf(obj).Elem() | ||
42 | val.FieldByIndex(field.Index()).Set(reflect.ValueOf(value).Elem()) | ||
43 | } | ||
44 | |||
45 | func (field *safeField) UnsafeSet(obj unsafe.Pointer, value unsafe.Pointer) { | ||
46 | panic("unsafe operation is not supported") | ||
47 | } | ||
48 | |||
49 | func (field *safeField) Get(obj interface{}) interface{} { | ||
50 | val := reflect.ValueOf(obj).Elem().FieldByIndex(field.Index()) | ||
51 | ptr := reflect.New(val.Type()) | ||
52 | ptr.Elem().Set(val) | ||
53 | return ptr.Interface() | ||
54 | } | ||
55 | |||
56 | func (field *safeField) UnsafeGet(obj unsafe.Pointer) unsafe.Pointer { | ||
57 | panic("does not support unsafe operation") | ||
58 | } | ||