-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpointer.go
40 lines (36 loc) · 899 Bytes
/
pointer.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
package pretty
import (
"reflect"
)
// PointerValueWriter is a [ValueWriter] that handles pointer values.
//
// It should be created with [NewPointerValueWriter].
type PointerValueWriter struct {
ValueWriter
// ShowAddr shows the address.
// Default: true.
ShowAddr bool
}
// NewPointerValueWriter creates a new [PointerValueWriter] with default values.
func NewPointerValueWriter(vw ValueWriter) *PointerValueWriter {
return &PointerValueWriter{
ValueWriter: vw,
ShowAddr: true,
}
}
// WriteValue implements [ValueWriter].
func (vw *PointerValueWriter) WriteValue(st *State, v reflect.Value) bool {
if v.Kind() != reflect.Pointer {
return false
}
if checkNil(st.Writer, v) {
return true
}
infos{
showAddr: vw.ShowAddr,
addr: uintptr(v.UnsafePointer()),
}.writeWithTrailingSpace(st)
writeArrow(st.Writer)
mustHandle(vw.ValueWriter(st, v.Elem()))
return true
}