Documentation
¶
Overview ¶
Package intconv provides functions for narrowing conversions between signed and unsigned integers.
Index ¶
- Variables
- func Int[T constraints.Integer](v T) (int, error)
- func Int16[T constraints.Integer](v T) (int16, error)
- func Int32[T constraints.Integer](v T) (int32, error)
- func Int64[T constraints.Integer](v T) (int64, error)
- func Int8[T constraints.Integer](v T) (int8, error)
- func Uint[T constraints.Integer](v T) (uint, error)
- func Uint16[T constraints.Integer](v T) (uint16, error)
- func Uint32[T constraints.Integer](v T) (uint32, error)
- func Uint64[T constraints.Integer](v T) (uint64, error)
- func Uint8[T constraints.Integer](v T) (uint8, error)
- type ConvertError
Constants ¶
This section is empty.
Variables ¶
var ( // ErrOverflow indicates that a value is too large to fit in the target type. ErrOverflow = errors.New("integer overflow") // ErrUnderflow indicates that a value is too small to fit in the target type. ErrUnderflow = errors.New("integer underflow") )
Functions ¶
func Int ¶
func Int[T constraints.Integer](v T) (int, error)
Int converts a value of type T to uint8. If the receiver integer overflows an ErrOverflow error is returned, and if it underflows an ErrUnderflow error is returned.
func Int16 ¶
func Int16[T constraints.Integer](v T) (int16, error)
Int16 converts a value of type T to int16. If the receiver integer overflows an ErrOverflow error is returned, and if it underflows an ErrUnderflow error is returned.
func Int32 ¶
func Int32[T constraints.Integer](v T) (int32, error)
Int32 converts a value of type T to int32. If the receiver integer overflows an ErrOverflow error is returned, and if it underflows an ErrUnderflow error is returned.
func Int64 ¶
func Int64[T constraints.Integer](v T) (int64, error)
Int64 converts a value of type T to int64. If the receiver integer overflows an ErrOverflow error is returned, and if it underflows an ErrUnderflow error is returned.
func Int8 ¶
func Int8[T constraints.Integer](v T) (int8, error)
Int8 converts a value of type T to int8. If the receiver integer overflows an ErrOverflow error is returned, and if it underflows an ErrUnderflow error is returned.
func Uint ¶
func Uint[T constraints.Integer](v T) (uint, error)
Uint converts a value of type T to uint. If the receiver integer overflows an ErrOverflow error is returned, and if it underflows an ErrUnderflow error is returned.
func Uint16 ¶
func Uint16[T constraints.Integer](v T) (uint16, error)
Uint16 converts a value of type T to uint16. If the receiver integer overflows an ErrOverflow error is returned, and if it underflows an ErrUnderflow error is returned.
func Uint32 ¶
func Uint32[T constraints.Integer](v T) (uint32, error)
Uint32 converts a value of type T to uint32. If the receiver integer overflows an ErrOverflow error is returned, and if it underflows an ErrUnderflow error is returned.
func Uint64 ¶
func Uint64[T constraints.Integer](v T) (uint64, error)
Uint64 converts a value of type T to uint64. If the receiver integer overflows an ErrOverflow error is returned, and if it underflows an ErrUnderflow error is returned.
func Uint8 ¶
func Uint8[T constraints.Integer](v T) (uint8, error)
Uint8 converts a value of type T to uint8. If the receiver integer overflows an ErrOverflow error is returned, and if it underflows an ErrUnderflow error is returned.
Types ¶
type ConvertError ¶
type ConvertError struct {
From, To reflect.Type
Value any
// contains filtered or unexported fields
}
ConvertError represents an error that occurs during type conversion. It contains information about the source and destination types and the value that caused the error.
If this is converted with errors.As, the underlying error kind will be resolvable as either ErrOverflow or ErrUnderflow with errors.Is.
func (*ConvertError) Error ¶
func (e *ConvertError) Error() string
func (*ConvertError) Unwrap ¶
func (e *ConvertError) Unwrap() error