golang how does the rune() function work

rune is a type in Go. It’s just an alias for int32, but it’s usually used to represent Unicode points. rune() isn’t a function, it’s syntax for type conversion into rune. Conversions in Go always have the syntax type() which might make them look like functions.

The first bit of code fails because conversion of strings to numeric types isn’t defined in Go. However conversion of strings to slices of runes/int32s is defined like this in language specification:

Converting a value of a string type to a slice of runes type yields a
slice containing the individual Unicode code points of the string.
[golang.org]

So your example prints a slice of runes with values 102, 111 and 111

Leave a Comment