I'm looking for integer conversion functions resembling this:
func narrow(x int64) (int32, error) { ... }
In this example, the function would return ((int32)(x), nil)
if x
fits into an int32
, and (nil, someError)
if it doesn't.
There seem to be a lot of conversions built into the language, but they all silently swallow overflows, rather than providing a reified error. Am I missing something?