ucast

package
v1.24.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolToString

func BoolToString(v *bool) string

BoolToString converts a bool to string

func Float32ToString

func Float32ToString(v *float32) string

Float32ToString converts a float32 to string

func Float64ToFloat32

func Float64ToFloat32(v *float64) float32

Float64ToFloat32 converts a float64 to float32

func Float64ToString

func Float64ToString(v *float64) string

Float64ToString converts a float64 to string

func Int16ToString

func Int16ToString(v *int16) string

Int16ToString converts an int64 to string

func Int32ToString

func Int32ToString(v *int32) string

Int32ToString converts an int64 to string

func Int64ToString

func Int64ToString(v *int64) string

Int64ToString converts an int64 to string

func Int8ToString

func Int8ToString(v *int8) string

Int8ToString converts an int64 to string

func IntToString

func IntToString(v *int) string

IntToString converts an int to string

func String

func String[R uconst.BasicType](str string) (R, error)

String converts the input string to a value of type R. It returns the converted value and an error if the conversion fails.

The type R must satisfy the uconst.BasicType constraint.

Example usage:

value, err := ucast.String[int]("123")
if err != nil {
    // handle error
}

func StringOrDef

func StringOrDef[R uconst.BasicType](str string, def R) (R, error)

StringOrDef attempts to convert the input string to a value of type R. If the conversion fails, it returns the default value def and an error.

The type R must satisfy the uconst.BasicType constraint.

Example usage:

value, err := ucast.StringOrDef[int]("invalid", 42)
// value == 42, err != nil

func StringToBool

func StringToBool(v *string) (bool, error)

StringToBool converts a string to bool

func StringToFloat32

func StringToFloat32(v *string) (float32, error)

StringToFloat32 converts a string to float32

func StringToFloat64

func StringToFloat64(v *string) (float64, error)

StringToFloat64 converts a string to float64

func StringToInt

func StringToInt(v *string) (int, error)

StringToInt converts a string to int

func StringToInt16

func StringToInt16(v *string) (int16, error)

StringToInt16 converts a string to int16

func StringToInt32

func StringToInt32(v *string) (int32, error)

StringToInt32 converts a string to int32

func StringToInt64

func StringToInt64(v *string) (int64, error)

StringToInt64 converts a string to int64

func StringToInt8

func StringToInt8(v *string) (int8, error)

StringToInt8 converts a string to int8

func StringToUint

func StringToUint(v *string) (uint, error)

StringToUint converts a string to uint

func StringToUint16

func StringToUint16(v *string) (uint16, error)

StringToUint16 converts a string to uint16

func StringToUint32

func StringToUint32(v *string) (uint32, error)

StringToUint32 converts a string to uint32

func StringToUint64

func StringToUint64(v *string) (uint64, error)

StringToUint64 converts a string to uint64

func StringToUint8

func StringToUint8(v *string) (uint8, error)

StringToUint8 converts a string to uint8

func Type

func Type[V uconst.BasicType](v V) string

Type converts the input value v of type V to its string representation.

The type V must satisfy the uconst.BasicType constraint.

Example usage:

str := ucast.Type       // "123"
str := ucast.Type[float64](3.14)  // "3.14"

func Uint16ToString

func Uint16ToString(v *uint16) string

Uint16ToString converts a uint16 to string

func Uint32ToString

func Uint32ToString(v *uint32) string

Uint32ToString converts a uint32 to string

func Uint64ToString

func Uint64ToString(v *uint64) string

Uint64ToString converts a uint64 to string

func Uint8ToString

func Uint8ToString(v *uint8) string

Uint8ToString converts a uint8 to string

func UintToString

func UintToString(v *uint) string

UintToString converts a uint to string

Types

This section is empty.

Jump to

Keyboard shortcuts

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