types

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2025 License: MIT Imports: 2 Imported by: 4

Documentation

Overview

Package types implements the functions, types, and interfaces for the module.

Package types implements the functions, types, and interfaces for the module.

Package types implements the functions, types, and interfaces for the module.

Package types implements the functions, types, and interfaces for the module.

Package types implements the functions, types, and interfaces for the module.

Package types implements the functions, types, and interfaces for the module.

Package types implements the functions, types, and interfaces for the module.

Package types implements the functions, types, and interfaces for the module.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cast added in v0.3.0

func Cast[T any](v any) (ret T, ok bool)

Cast attempts to convert a value to the specified type. If the conversion is successful, it returns the converted value and true. If the conversion fails, it returns the original value and false.

func CastOr added in v0.3.0

func CastOr[T any](v any, def T) T

CastOr attempts to convert a value to the specified type. If the conversion is successful, it returns the converted value. If the conversion fails, it returns the default value.

func CastOrZero added in v0.3.0

func CastOrZero[T comparable](v any) (zero T)

CastOrZero attempts to convert a value to the specified type. If the conversion is successful, it returns the converted value. If the conversion fails, it returns a zero value of the specified type.

func MustCast added in v0.3.0

func MustCast[T any](v any) T

MustCast attempts to convert a value to the specified type. If the conversion is successful, it returns the converted value. If the conversion fails, it panics with the message.

func StringLike added in v0.3.0

func StringLike[T String](t T) string

StringLike converts a string-like type to a string.

func Zero

func Zero[T any]() (zero T)

Zero is the zero value for a type.

func ZeroOr

func ZeroOr[T comparable](v T, def T) T

ZeroOr returns def if v is the zero value. Decrypted: use cmp.ZeroOr instead.

Types

type Boolean

type Boolean interface {
	Object

	~bool
}

Boolean is an interface that represents a boolean type. It is implemented by the built-in bool type.

type Complex

type Complex = interface {
	Object
	constraints.Complex
}

Complex is an interface that represents a complex64 or complex128 number.

type Const

type Const interface {
	Number | Boolean | ~string
}

Const is an interface that represents a value that is either a Number, a Boolean, or a string. It is used to define constants in Go.

type Float

type Float = interface {
	Object
	constraints.Float
}

Float is an interface that represents a float32 or float64.

type Integer

type Integer = interface {
	Object
	constraints.Integer
}

Integer is an interface that represents an integer type.

type Map added in v0.2.5

type Map[K comparable, V any] interface {
	Object
	~map[K]V
}

type Number

type Number interface {
	Object
	Float | Integer | Complex
}

Number is an interface that represents any number type. It includes all the interfaces defined above.

type Object added in v0.2.5

type Object interface {
	any
}

type Ordered

type Ordered = interface {
	Object
	constraints.Ordered
}

Ordered is an interface that represents any ordered type.

type Signed

type Signed = interface {
	Object
	constraints.Signed
}

Signed is an interface that represents a signed integer type.

type Slice

type Slice[T any] interface {
	~[]T
}

type String

type String interface {
	Object
	~string | ~[]byte | ~[]rune
}

String is an interface that represents a string-like type. It can be a string, a byte slice, or a rune slice.

type Unsigned

type Unsigned = interface {
	Object
	constraints.Unsigned
}

Unsigned is an interface that represents an unsigned integer type.

Jump to

Keyboard shortcuts

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