November 2017
Intermediate to advanced
264 pages
5h 45m
English
Rust is an expression-oriented language, which means that most pieces of code are in fact expressions, that is, they compute a value and return that value. However, expressions on themselves do not form meaningful code; they must be used in statements.
let bindings like the following are declaration statements; they are not expressions:
// see Chapter 2/code/expressions.rs let a = 2; // a binds to 2 let b = 5; // b binds to 5 let n = a + b; // n binds to 7
But, here, a + b is an expression and, if we omit the semicolon at the end, the resulting value (here the value 7) is returned. This is often used when a function needs to return its value (see examples in the next chapter). Ending an expression with a semicolon like a + b; ...
Read now
Unlock full access