Summary
-
Rust uses a lot of special symbols like
{
and)
-
Many of these symbols come in pairs
-
These pairs of symbols need to nest inside each other
-
It’s good practice to follow layout rules to make your code easier to read
-
The
rustfmt
tool can help you get the layout right -
You can use
//
or/* */
to add comments to your code -
An expression is evaluated to a value of a specific type
-
Most of our Rust code is writing expressions
-
You can draw out expressions as trees, and then evaluate from the bottom up
-
Variables are a convenient way to capture expression results and give them useful names
-
Some expressions cause effects to happen
-
All expressions produce a result
-
But when an expression has nothing useful to produce, it produces
()
, aka unit -
The body of a function is a block
-
Blocks can contain multiple statements, and end with an optional expression
-
The semicolon throws away the result of an expression
-
If you end your block with an expression without a semicolon, it will produce that value, otherwise it produces unit