"An algorithm must be seen to be believed"
– Donald Knuth
Before we go into more dense topics in this chapter, we'll first discuss some of the type system tidbits in statically typed programming languages in general, with focus on Rust. Some of these topics may already be familiar to you from Chapter 1, Getting Started with Rust, but we're going to dig into the details here.
Despite being a mix of statements and expressions, Rust is primarily an expression-oriented language. This means that most constructs are expressions that return a value. It's also a language that uses C-like braces {}
, to introduce new scope for variables in a program. Let's get these concepts straight before we talk more about them later in this chapter.
A block expression (hereby referred as blocks) is any item that starts with {
and ends with }
. In Rust, they include if else
expressions, match expressions, while
loops, loops, bare {}
blocks, functions, methods, and closures,...