quintodrome/utils/number/number.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

17 lines
317 B
Go
Raw Normal View History

package number
2023-01-13 17:40:24 -09:00
import (
"strconv"
2023-01-13 17:40:24 -09:00
)
// Integer is a constraint that permits any integer type.
type Integer interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 |
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}
func ParseInt[T Integer](s string) T {
r, _ := strconv.ParseInt(s, 10, 64)
return T(r)
}