Documentation
¶
Index ¶
- func Cast[F, T IConvertible](i F, f CastFunc[F, T]) T
- func CastRef[F, T IConvertible](i *F, f CastFunc[F, T]) *T
- func RobustCast[F, T IConvertible](i F) (c T, err error)
- func RobustCastRef[F, T IConvertible](i *F) (c *T, err error)
- func ToFloat32[C IConvertible](i C) float32
- func ToFloat32Ref[C IConvertible](i *C) *float32
- func ToFloat64[C IConvertible](i C) float64
- func ToFloat64Ref[C IConvertible](i *C) *float64
- func ToInt[C IConvertible](i C) int
- func ToInt8[C IConvertible](i C) int8
- func ToInt8Ref[C IConvertible](i *C) *int8
- func ToInt16[C IConvertible](i C) int16
- func ToInt16Ref[C IConvertible](i *C) *int16
- func ToInt32[C IConvertible](i C) int32
- func ToInt32Ref[C IConvertible](i *C) *int32
- func ToInt64[C IConvertible](i C) int64
- func ToInt64Ref[C IConvertible](i *C) *int64
- func ToIntRef[C IConvertible](i *C) *int
- func ToUint[C IConvertible](i C) uint
- func ToUint8[C IConvertible](i C) uint8
- func ToUint8Ref[C IConvertible](i *C) *uint8
- func ToUint16[C IConvertible](i C) uint16
- func ToUint16Ref[C IConvertible](i *C) *uint16
- func ToUint32[C IConvertible](i C) uint32
- func ToUint32Ref[C IConvertible](i *C) *uint32
- func ToUint64[C IConvertible](i C) uint64
- func ToUint64Ref[C IConvertible](i *C) *uint64
- func ToUintRef[C IConvertible](i *C) *uint
- type CastFunc
- type IConvertabledeprecated
- type IConvertible
- type IFloat
- type IInteger
- type INumber
- type ISignedInteger
- type IUnsignedInteger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cast ¶ added in v1.154.0
func Cast[F, T IConvertible](i F, f CastFunc[F, T]) T
Cast converts an IConvertible value to another IConvertible type using the supplied conversion function.
func CastRef ¶ added in v1.154.0
func CastRef[F, T IConvertible](i *F, f CastFunc[F, T]) *T
CastRef converts a reference to an IConvertible value to a reference to another IConvertible type using the supplied conversion function. A nil input returns nil.
func RobustCast ¶ added in v1.154.0
func RobustCast[F, T IConvertible](i F) (c T, err error)
RobustCast converts an IConvertible value to the target type T by dispatching to the appropriate safe helper for T.
Conversions to bounded integer and float32 types use the corresponding helper, so out-of-range values are clamped to the nearest valid boundary. If types are not supported, an error is returned.
func RobustCastRef ¶ added in v1.154.0
func RobustCastRef[F, T IConvertible](i *F) (c *T, err error)
RobustCastRef converts a reference to an IConvertible value to a reference to the target type T by dispatching to the appropriate safe helper for T. A nil input returns nil. If types are not supported, an error is returned.
func ToFloat32 ¶ added in v1.154.0
func ToFloat32[C IConvertible](i C) float32
ToFloat32 attempts to convert an IConvertible value to a float32. If the converted value falls outside the range of float32, the nearest boundary value is returned instead.
func ToFloat32Ref ¶ added in v1.154.0
func ToFloat32Ref[C IConvertible](i *C) *float32
ToFloat32Ref attempts to convert a reference to an IConvertible value to a reference to a float32. A nil input returns nil.
func ToFloat64 ¶ added in v1.147.0
func ToFloat64[C IConvertible](i C) float64
ToFloat64 attempts to convert an IConvertible value to a float64.
func ToFloat64Ref ¶ added in v1.154.0
func ToFloat64Ref[C IConvertible](i *C) *float64
ToFloat64Ref attempts to convert a reference to an IConvertible value to a reference to a float64. A nil input returns nil.
func ToInt ¶
func ToInt[C IConvertible](i C) int
ToInt attempts to convert an IConvertible value to an int. If the converted value falls outside the range of int, the nearest boundary value is returned instead.
func ToInt8 ¶
func ToInt8[C IConvertible](i C) int8
ToInt8 attempts to convert an IConvertible value to an int8. If the converted value falls outside the range of int8, the nearest boundary value is returned instead.
func ToInt8Ref ¶ added in v1.154.0
func ToInt8Ref[C IConvertible](i *C) *int8
ToInt8Ref attempts to convert a reference to an IConvertible value to a reference to an int8. A nil input returns nil.
func ToInt16 ¶
func ToInt16[C IConvertible](i C) int16
ToInt16 attempts to convert an IConvertible value to an int16. If the converted value falls outside the range of int16, the nearest boundary value is returned instead.
func ToInt16Ref ¶ added in v1.154.0
func ToInt16Ref[C IConvertible](i *C) *int16
ToInt16Ref attempts to convert a reference to an IConvertible value to a reference to an int16. A nil input returns nil.
func ToInt32 ¶
func ToInt32[C IConvertible](i C) int32
ToInt32 attempts to convert an IConvertible value to an int32. If the converted value falls outside the range of int32, the nearest boundary value is returned instead.
func ToInt32Ref ¶ added in v1.154.0
func ToInt32Ref[C IConvertible](i *C) *int32
ToInt32Ref attempts to convert a reference to an IConvertible value to a reference to an int32. A nil input returns nil.
func ToInt64 ¶
func ToInt64[C IConvertible](i C) int64
ToInt64 attempts to convert an IConvertible value to an int64. If the converted value falls outside the range of int64, the nearest boundary value is returned instead.
func ToInt64Ref ¶ added in v1.154.0
func ToInt64Ref[C IConvertible](i *C) *int64
ToInt64Ref attempts to convert a reference to an IConvertible value to a reference to an int64. A nil input returns nil.
func ToIntRef ¶ added in v1.154.0
func ToIntRef[C IConvertible](i *C) *int
ToIntRef attempts to convert a reference to an IConvertible value to a reference to an int. A nil input returns nil.
func ToUint ¶
func ToUint[C IConvertible](i C) uint
ToUint attempts to convert an IConvertible value to a uint. If the converted value falls outside the range of uint, the nearest boundary value is returned instead.
func ToUint8 ¶
func ToUint8[C IConvertible](i C) uint8
ToUint8 attempts to convert an IConvertible value to a uint8. If the converted value falls outside the range of uint8, the nearest boundary value is returned instead.
func ToUint8Ref ¶ added in v1.154.0
func ToUint8Ref[C IConvertible](i *C) *uint8
ToUint8Ref attempts to convert a reference to an IConvertible value to a reference to a uint8. A nil input returns nil.
func ToUint16 ¶
func ToUint16[C IConvertible](i C) uint16
ToUint16 attempts to convert an IConvertible value to a uint16. If the converted value falls outside the range of uint16, the nearest boundary value is returned instead.
func ToUint16Ref ¶ added in v1.154.0
func ToUint16Ref[C IConvertible](i *C) *uint16
ToUint16Ref attempts to convert a reference to an IConvertible value to a reference to a uint16. A nil input returns nil.
func ToUint32 ¶
func ToUint32[C IConvertible](i C) uint32
ToUint32 attempts to convert an IConvertible value to a uint32. If the converted value falls outside the range of uint32, the nearest boundary value is returned instead.
func ToUint32Ref ¶ added in v1.154.0
func ToUint32Ref[C IConvertible](i *C) *uint32
ToUint32Ref attempts to convert a reference to an IConvertible value to a reference to a uint32. A nil input returns nil.
func ToUint64 ¶
func ToUint64[C IConvertible](i C) uint64
ToUint64 attempts to convert an IConvertible value to a uint64. If the converted value falls outside the range of uint64, the nearest boundary value is returned instead.
func ToUint64Ref ¶ added in v1.154.0
func ToUint64Ref[C IConvertible](i *C) *uint64
ToUint64Ref attempts to convert a reference to an IConvertible value to a reference to a uint64. A nil input returns nil.
func ToUintRef ¶ added in v1.154.0
func ToUintRef[C IConvertible](i *C) *uint
ToUintRef attempts to convert a reference to an IConvertible value to a reference to a uint. A nil input returns nil.
Types ¶
type CastFunc ¶ added in v1.154.0
type CastFunc[F, T IConvertible] func(F) T
CastFunc defines a function that converts a value of type F to type T, where both types satisfy IConvertible.
type IConvertable
deprecated
type IConvertable = IConvertible
Deprecated: IConvertable is an alias for IConvertible. Use IConvertible instead
type IConvertible ¶ added in v1.154.0
type IConvertible interface {
INumber
}
IConvertible is an alias for everything that can be converted
type IInteger ¶
type IInteger interface {
ISignedInteger | IUnsignedInteger
}
IInteger is an alias for the all unsigned and signed integers
type ISignedInteger ¶
ISignedInteger is an alias for all signed integers: int, int8, int16, int32, and int64 types.