Description
Quoting the Rust Guide:
We expected an integer, but we got (). () is pronounced 'unit', and is a special type in Rust's type system. () is different than null in other languages, because () is distinct from other types. For example, in C, null is a valid value for a variable of type int.
This has two separate problems. First, C has no value named null
; C has NULL
instead. Second, and more importantly, NULL
is not a valid value for a variable of type int
in C, because NULL
has pointer type (typically ((void *)0)
).
Making a direct analogy to C here requires Rust concepts not yet explained at this point in the guide (pointers). Two possible alternatives: either generalize the explanation a bit with less specific references to C and Rust syntax ("For example, any C string can be NULL, making it invalid to access as a string; a Rust string cannot be null and is always a valid string."). or make an analogy to another language that uses boxed types by default, such as Java.