Skip to content

Commit

Permalink
add missing methods
Browse files Browse the repository at this point in the history
  • Loading branch information
taowen committed Feb 22, 2018
1 parent 832b823 commit 5713569
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions reflect2/reflect2.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Type interface {
UnsafeIsNil(ptr unsafe.Pointer) bool
Set(obj interface{}, val interface{})
UnsafeSet(ptr unsafe.Pointer, val unsafe.Pointer)
AssignableTo(anotherType Type) bool
}

type ListType interface {
Expand Down Expand Up @@ -215,6 +216,10 @@ func Type2(type1 reflect.Type) Type {
return ConfigUnsafe.Type2(type1)
}

func PtrTo(typ Type) Type {
return Type2(reflect.PtrTo(typ.Type1()))
}

func PtrOf(obj interface{}) unsafe.Pointer {
return unpackEFace(obj).data
}
Expand Down
4 changes: 4 additions & 0 deletions reflect2/safe_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@ func (type2 *safeType) Set(obj interface{}, val interface{}) {

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())
}

0 comments on commit 5713569

Please sign in to comment.