Chapter 1: An Introduction to Rust from a Python Perspective
Due to its speed and safety, it is no surprise that Rust is the new language gaining in popularity. However, with success comes criticism. Despite Rust's popularity as an impressive language, it has also gained the label of being hard to learn, an idea which isn't quite grounded in reality.
In this chapter, we will cover all of Rust's quirks that will be new to a Python developer. If Python is your main language, concepts such as basic memory management and typing can initially slow down your ability to quickly write productive Rust code due to the compiler failing to compile the code. However, this can quickly be overcome by learning the rules around Rust features, such as variable ownership, lifetimes, and so on, as Rust is a memory-safe language. Consequently, we must keep track of our variables as they usually get deleted instantly when they go out of scope. If this does not make sense yet, don't worry; we will cover this concept in the Keeping track of scopes and lifetimes section.
In this chapter, we will also be covering the basics of syntax, while you will be setting up a Rust environment on your own computer in the next chapter. Do not worry though, you can code all the examples in this chapter on the free online Rust playground.
In particular, we will cover the following topics in this chapter:
- Understanding the differences between Python and Rust
- Understanding variable ownership
- Keeping track of scopes and lifetimes
- Building structs as opposed to objects
- Metaprogramming with macros instead of decorators