Numeric literals can be type annotated by adding the type as a suffix, with the
exception of usize
that uses the usize
suffix and isize
that uses the
isize
suffix.
The type of unsuffixed numeric literals will depend on how they are used. If no
constraint exists, the compiler will use i32
for integers, and f64
for
floating-point numbers.
There are some concepts used in the previous code that haven't been explained yet, here's a brief explanation for the impatient readers:
fun(&foo)
is used to pass an argument to a function by reference, rather
than by value (fun(foo)
). For more details see borrowing.std::mem::size_of_val
is a function, but called with its full path. Code
can be split in logical units called modules. In this case, the
size_of_val
function is defined in the mem
module, and the mem
module
is defined in the std
crate. For more details, see
modules and crates.