on 28be21f help sign in
34 lines 873 B history raw
1// Copyright 2018, The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
5package value
7import (
8 "reflect"
9 "unsafe"
12// Pointer is an opaque typed pointer and is guaranteed to be comparable.
13type Pointer struct {
14 p unsafe.Pointer
15 t reflect.Type
18// PointerOf returns a Pointer from v, which must be a
19// reflect.Ptr, reflect.Slice, or reflect.Map.
20func PointerOf(v reflect.Value) Pointer {
21 // The proper representation of a pointer is unsafe.Pointer,
22 // which is necessary if the GC ever uses a moving collector.
23 return Pointer{unsafe.Pointer(v.Pointer()), v.Type()}
26// IsNil reports whether the pointer is nil.
27func (p Pointer) IsNil() bool {
28 return p.p == nil
31// Uintptr returns the pointer as a uintptr.
32func (p Pointer) Uintptr() uintptr {
33 return uintptr(p.p)