Rust Essentials(Second Edition)
上QQ阅读APP看书,第一时间看更新

Using Variables and Types

In this chapter, we look at the basic building blocks of a Rust program, like variables and types. We discuss variables of primitive types, whether their type has to be declared or not, and the scope of variables. Immutability, one of the cornerstones of Rust's safety strategy, is also discussed and illustrated.

We will cover the following topics:

  • Comments
  • Global constants
  • Values and primitive types
  • Binding variables to values
  • Scope of a variable and shadowing
  • Type checking and conversions
  • Expressions
  • The stack and the heap

Our code examples will center on building a text-based game called Monster Attack.