generics

package
v0.0.0-...-114fa82 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2024 License: Apache-2.0 Imports: 3 Imported by: 78

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cast

func Cast[T any](o any) T

Cast asserts a type given by a type parameter for a value This is not directly suppoerted by Go.

func [O any](...) {
   x := i.(O)
}

func CastPointer

func CastPointer[I any, E any, P PointerType[E]](e P) I

CastPointer maps a pointer P to an interface type I avoiding typed nil pointers. Nil pointers will be mapped to nil interfaces.

func CastPointerR

func CastPointerR[I any, E any, P PointerType[E]](e P, err error) (I, error)

CastPointerR maps a pointer P to an interface type I for a factory function with an additional error result avoiding typed nil pointers. Nil pointers will be mapped to nil interfaces.

func CastR

func CastR[T any](o any, err error) (T, error)

CastR cast a result type to a dedicated Type T for a factory function with an additional error result Nil will be mapped to the initial value of the target type

func Pointer

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

func TryCast

func TryCast[T any](o any) (T, bool)

TryCast is like Cast, but reports whether the assertion is possible or not.

func TryCastE

func TryCastE[T any](o any) (T, error)

TryCastE casts one type parameter to another type parameter, which have a subtype relation. This cannot be described by type parameter constraints in Go, because constraints may not be type parameters again.

func TypeOf

func TypeOf[T any]() reflect.Type

Types

type PointerType

type PointerType[P any] interface {
	*P
}

Jump to

Keyboard shortcuts

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