Control Flow
Expressions
Blocks have value
Operator precedence table is in the reference manual. 18 levels. Left associativity. Left-to-right evaluation?
Conversion is mostly explicit through
as
. Only conversions that are "safe" work (where safe has a somewhat non-intuitive definition)Reference magic happens
- Auto dereference in certain situations as discussed earlier
- Auto reference conversions in certain situations, e.g.
String
,Vec
,Box
Expressions and Control Flow
In Rust, some of what we would normally do with control flow is done with simple expressions. This is part of Rust's functional-language heritage
if
is an expression type- "method" chaining is a standard mechanism
"Method" Chaining
Many Rust operations are used in an "object-oriented style":
"hello".to_uppercase()
vs
to_uppercase("hello")
This allows stringing together expressions in more readable syntax (and also facilitates proper borrowing/sharing).
https://play.rust-lang.org/?gist=fe8f51647a4cd3268c74e2276bef9089&version=undefined
Explicit Control Flow
if
-else
if let
,while let
match
while
loop
for
and iterators
Last modified: Thursday, 15 April 2021, 12:54 AM