utils

package
v0.0.0-...-4cbc1f5 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2024 License: Apache-2.0 Imports: 2 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAs

func GetAs[T any](obj any) (T, bool)

GetAs returns `obj` as type `T`. Uses Golang built-in type assertion.

func Implements

func Implements[T any](obj any) bool

Implements returns whether `obj` implements `T`. Uses Golang built-in type assertion.

func Max

func Max[T Numerical](a, b T) T

func Min

func Min[T Numerical](a, b T) T

func MustGetAs

func MustGetAs[T any](obj any) T

MustGetAs returns `obj` as type `T`. Will panic if `obj` is not of type `T`. Uses Golang built-in type assertion.

func UnsafeBytesToStr

func UnsafeBytesToStr(b []byte) string

UnsafeBytesToStr is meant to make a zero allocation conversion from []byte -> string to speed up operations, it is not meant to be used generally, but for a specific pattern to delete keys from a map.

func UnsafeStrToBytes

func UnsafeStrToBytes(s string) []byte

UnsafeStrToBytes uses unsafe to convert string into byte array. Returned bytes must not be altered after this function is called as it will cause a segmentation fault.

Types

type Numerical

type Numerical interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
}

Jump to

Keyboard shortcuts

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