intconv

package
v0.0.0-...-e90178e Latest Latest
Warning

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

Go to latest
Published: May 16, 2025 License: Apache-2.0, MIT Imports: 5 Imported by: 0

Documentation

Overview

Package intconv provides functions for narrowing conversions between signed and unsigned integers.

Index

Constants

This section is empty.

Variables

View Source
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

Jump to

Keyboard shortcuts

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