Documentation
¶
Overview ¶
Package converters provides safe type conversion functions.
Index ¶
- Variables
- func SafeInt16FromInt64(value int64) (int16, error)
- func SafeInt32FromInt64(value int64) (int32, error)
- func SafeInt64FromUint64(value uint64) (int64, error)
- func SafeInt8FromInt64(value int64) (int8, error)
- func SafeIntFromInt64(value int64) (int, error)
- func SafeIntFromUint64(value uint64) (int, error)
- func SafeUint16FromInt64(value int64) (uint16, error)
- func SafeUint32FromInt64(value int64) (uint32, error)
- func SafeUint32FromUint64(value uint64) (uint32, error)
- func SafeUint64FromInt(value int) (uint64, error)
- func SafeUint64FromInt64(value int64) (uint64, error)
- func SafeUint8FromInt64(value int64) (uint8, error)
- func SafeUintFromInt64(value int64) (uint, error)
- func ToInt[T Integer](value T) (int, error)
- func ToInt32[T Integer](value T) (int32, error)
- func ToInt64[T Integer](value T) (int64, error)
- func ToUint[T Integer](value T) (uint, error)
- func ToUint32[T Integer](value T) (uint32, error)
- func ToUint64[T Integer](value T) (uint64, error)
- type Integer
- type Signed
- type Unsigned
Constants ¶
This section is empty.
Variables ¶
var ErrNegativeValue = ewrap.New("negative values cannot be converted to unsigned integers")
ErrNegativeValue is returned when attempting to convert a negative number to an unsigned type.
var ErrOverflow = ewrap.New("value overflows target type")
ErrOverflow is returned when a value exceeds the target type's bounds.
Functions ¶
func SafeInt16FromInt64 ¶ added in v1.0.1
SafeInt16FromInt64 converts an int64 to int16, ensuring the value fits in the target type.
func SafeInt32FromInt64 ¶ added in v1.0.1
SafeInt32FromInt64 converts an int64 to int32, ensuring the value fits in the target type.
func SafeInt64FromUint64 ¶ added in v1.0.1
SafeInt64FromUint64 converts a uint64 to int64, ensuring the value fits in the target type.
func SafeInt8FromInt64 ¶ added in v1.0.1
SafeInt8FromInt64 converts an int64 to int8, ensuring the value fits in the target type.
func SafeIntFromInt64 ¶
SafeIntFromInt64 converts an int64 to int, ensuring the value fits in the target type.
func SafeIntFromUint64 ¶ added in v1.0.1
SafeIntFromUint64 converts a uint64 to int, ensuring the value fits in the target type.
func SafeUint16FromInt64 ¶ added in v1.0.1
SafeUint16FromInt64 converts an int64 to uint16 while guarding against negative values and overflow.
func SafeUint32FromInt64 ¶ added in v1.0.1
SafeUint32FromInt64 converts an int64 to uint32 while guarding against negative values and overflow.
func SafeUint32FromUint64 ¶ added in v1.0.1
SafeUint32FromUint64 converts a uint64 to uint32, ensuring the value fits in the target type.
func SafeUint64FromInt ¶
SafeUint64FromInt converts an int to uint64 while guarding against negative values and overflow.
func SafeUint64FromInt64 ¶
SafeUint64FromInt64 converts an int64 to uint64 while guarding against negative values.
func SafeUint8FromInt64 ¶ added in v1.0.1
SafeUint8FromInt64 converts an int64 to uint8 while guarding against negative values and overflow.
func SafeUintFromInt64 ¶ added in v1.0.1
SafeUintFromInt64 converts an int64 to uint while guarding against negative values and overflow.
func ToInt ¶ added in v1.0.4
ToInt converts any integer type to int, ensuring the value fits in the target type.
func ToInt32 ¶ added in v1.0.4
ToInt32 converts any integer type to int32, ensuring the value fits in the target type.
func ToInt64 ¶ added in v1.0.4
ToInt64 converts any integer type to int64, guarding against overflow for unsigned inputs.
func ToUint ¶ added in v1.0.4
ToUint converts any integer type to uint while guarding against negative values and overflow.
Types ¶
type Integer ¶ added in v1.0.4
Integer represents all integer types supported by the generic converters.