shithub: furgit

ref: 3ce59c3248dec0eb0f918c42f37f53bc2ac20425
dir: /internal/intconv/u32_u8.go/

View raw version
package intconv

import (
	"fmt"
	"math"
)

// Uint32ToUint8 converts v to uint8, returning an error if it overflows.
func Uint32ToUint8(v uint32) (uint8, error) {
	if v > math.MaxUint8 {
		return 0, fmt.Errorf("intconv: uint32 %d overflows uint8", v)
	}

	return uint8(v), nil
}