void type
On this page
The language's pre-defined void type is used whenever we want to represent that no value is expected. This is useful in several circumstances:
- As the return type for a function or method that accomplishes some effect, but returns no value.
- As the value for a generic type for which it makes sense to substitute in the void type. For example, a function that returns no value on success, but returns an E type on failure would have a return type of Result[void, E].
There is only one possible value for a void type: nil. Any return or break statement that specifies no expression value is effectively returning a value of nil.
Zero-sized values may not be stored in memory. For this reason, one may not define a variable of type void nor allocate space for a new value of type void. However, it is fine for a struct to define a void-typed field, so long as at least one other field has a non-zero-sized type.
Never#
Never is the return type of a function that does not return at all: the core library's panic, or the C library's abort. It is void wherever a value is asked of it, and says one thing more: control does not come back from the call. So a call to one may end a block that must produce a value, which then has no value on that path, and a function declared to return Never must end in such a call. Panics has examples.