types

package
v0.4.27 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: LGPL-2.1 Imports: 5 Imported by: 20

Documentation

Overview

Package types 提供反射类型辅助函数。

Package types 封装了零值创建、指针包装、类型名和完整限定名等常见反射操作,用于 原型系统、断言注入和代码生成支持逻辑。

当框架需要在运行期根据实例或 reflect.Type 推导名称、创建零值或写出全限定类型名时, 通常会使用该包。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool2Int

func Bool2Int[T Integer](b bool) T

Bool2Int 将 false 转为 0、true 转为 1,并返回目标整数类型。

func Bytes2String

func Bytes2String(b []byte) string

Bytes2String 将字节切片零拷贝重解释为字符串。

返回值与 b 共享存储;字符串存活期间不得修改或并发写入 b。

func FullName

func FullName(i any) string

FullName 返回值或 reflect.Type 的“包导入路径.类型名”;参数没有动态类型时 panic。

func FullNameRT

func FullNameRT(t reflect.Type) string

FullNameRT 返回 t 的“包导入路径.类型名”;无包路径时仅返回类型名。

func FullNameT

func FullNameT[T any]() string

FullNameT 返回 T 的“包导入路径.类型名”。

func Int2Bool

func Int2Bool[T Integer](v T) bool

Int2Bool 将 0 转为 false、其他整数转为 true。

func Name

func Name(i any) string

Name 返回值或 reflect.Type 的具名类型名;参数没有动态类型时 panic。

func NameRT

func NameRT(t reflect.Type) string

NameRT 返回反射类型的具名类型名;t 为 nil 时 panic。

func NameT

func NameT[T any]() string

NameT 返回 T 的具名类型名。

func New added in v0.3.65

func New[T any]() *T

New 返回指向新 T 零值的指针。

func Panic2Err

func Panic2Err(panicInfo any) error

Panic2Err 将 recover 的结果转换为 error;nil 保持为 nil。

func Pointer added in v0.4.27

func Pointer[T any](src T) *T

Pointer 返回指向 src 副本的指针。

func String2Bytes

func String2Bytes(s string) []byte

String2Bytes 将字符串零拷贝重解释为字节切片。

返回值与 s 共享存储,绝不能修改;违反约束可能导致崩溃或未定义行为。

func WriteFullName added in v0.3.65

func WriteFullName(sb *strings.Builder, i any)

WriteFullName 将值或 reflect.Type 的完整名称写入 sb。

func WriteFullNameRT

func WriteFullNameRT(sb *strings.Builder, t reflect.Type)

WriteFullNameRT 将 t 的完整名称写入 sb。

func WriteFullNameT

func WriteFullNameT[T any](sb *strings.Builder)

WriteFullNameT 将 T 的完整名称写入 sb。

func Zero added in v0.3.65

func Zero[T any]() T

Zero 返回 T 的零值。

Types

type Integer added in v0.3.85

type Integer interface {
	Signed | Unsigned
}

Integer 约束所有整数类型。

type Signed added in v0.3.85

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

Signed 约束所有有符号整数及其自定义底层类型。

type Unsigned added in v0.3.85

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

Unsigned 约束所有无符号整数及其自定义底层类型。

Jump to

Keyboard shortcuts

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