Skip to content

std/convert

import "std/convert" as convert;

The module overloads conversion functions for their supported input types.

FunctionAccepted inputs
toString(value) StringString, Bool, Char, integer, and floating-point types
toInt(value) IntBool, Char, integer, and floating-point types
toFloat(value) FloatBool, Char, integer, and floating-point types
toFloat64(value) Float64Bool, Char, integer, and floating-point types
toBool(value) BoolString, Char, Bool, integer, and floating-point types
toChar(value) CharChar and Int

Numeric conversions use the target type’s normal conversion rules. toBool(String) is true only for "true" and "1".

parseInt(raw: String) Int!ParseIntError accepts surrounding whitespace and an optional + or - sign:

import "std/convert" as convert;
fun main() Int {
var port = convert.parseInt("8080") or err {
eprintln("invalid port");
return 1;
};
return port;
}

ParseIntError has Empty and InvalidDigit variants.