iface

package
v0.3.97 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2025 License: LGPL-2.1 Imports: 3 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cache2Iface

func Cache2Iface[T any](c Cache) T

Cache2Iface 接口存储器(Cache)转换为接口

Types

type Cache

type Cache [2]unsafe.Pointer

Cache 接口存储器,因为Golang原生的接口转换性能较差,所以在某些性能要求较高的场景下,需要尽量较少接口转换。 如果必须转换接口,那么目前可用的优化方案是,在编码时已知接口类型,可以将接口转换为[2]unsafe.Pointer,使用时再转换回接口。 Cache套件就是使用此优化方案,注意不安全,在明确了解此方案时再使用。

var (
	NilCache Cache // nil cache
)

func Iface2Cache

func Iface2Cache[T any](i T) Cache

Iface2Cache 接口转换为接口存储器(Cache)

type Face

type Face[T any] struct {
	Iface T     // 接口
	Cache Cache // 接口存储器
}

Face 面,用于存储接口与接口存储器,接口用于断言转换类型,接口存储器用于重解释接口

func MakeFaceT added in v0.2.91

func MakeFaceT[T any](iface T) Face[T]

MakeFaceT 创建面(Face),接口存储器重解释接口与接口类型相同

func MakeFaceTC added in v0.2.91

func MakeFaceTC[T, C any](iface T, cache C) Face[T]

MakeFaceTC 创建面(Face),接口存储器重解释接口与接口类型可以不同

func MakeFaceTReflectC added in v0.2.91

func MakeFaceTReflectC[T, C any](iface T) Face[T]

MakeFaceTReflectC 创建面(Face),自动反射获取接口存储器

func (*Face[T]) IsNil

func (f *Face[T]) IsNil() bool

IsNil 是否为空

type FaceAny

type FaceAny = Face[any]

FaceAny face with any

func MakeFaceAny

func MakeFaceAny[C any](cache C) FaceAny

MakeFaceAny 创建 FaceAny

Jump to

Keyboard shortcuts

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