ptrKit

package
v2.8.152 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertNotNilAndIsPointer

func AssertNotNilAndIsPointer(ptr interface{}) error

AssertNotNilAndIsPointer

合法的传参: (1) ptr != nil(值非nil) (2) ptr的类型为"指针"

func ExtractPointer added in v2.8.152

func ExtractPointer(value any) any

ExtractPointer 返回传入interface的底层值.

func IsPointer

func IsPointer(obj interface{}) bool

IsPointer 传参的类型是否为指针?

PS: 传参的值无影响,即使其为nil.

@param obj 可以为nil

e.g.

type bean struct {
}
var b *bean = nil
fmt.Println(ptrKit.IsPointer(b)) 				// true(类型为指针,虽然值为nil)

fmt.Println(ptrKit.IsPointer(interface{}(nil))) // false

func IsPointer1

func IsPointer1(obj interface{}) bool

IsPointer1 *

  • 判断参数obj是否为指针(pointer).
  • 参考:github.com/json-iterator/go => reflect.go => func (iter *Iterator) ReadVal(obj interface{}) *
  • @param obj nil => false

func IsPointer2

func IsPointer2(obj interface{}) bool

IsPointer2

e.g. (nil) => false

func Of added in v2.8.152

func Of[T any](v T) *T

Of 返回传入参数的指针值.

func ToString

func ToString(ptr interface{}) string

ToString 指针 => 指针的地址字符串(十六进制表示,前缀 0x)

e.g.

tmp := 1
(&tmp) => "0xc00000a228"

e.g.1

(nil) => "%!p(<nil>)"

func UnwarpOr added in v2.8.152

func UnwarpOr[T any](p *T, fallback T) T

UnwarpOr 返回指针的值,如果指针为零值,则返回fallback.

func UnwarpOrDefault added in v2.8.152

func UnwarpOrDefault[T any](p *T) T

UnwarpOrDefault 返回指针的值,如果指针为零值,则返回相应零值.

func Unwrap added in v2.8.152

func Unwrap[T any](p *T) T

Unwrap 返回传入指针指向的值.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL