-
Book Overview & Buying
-
Table Of Contents
Rust Web Programming - Third Edition
By :
With Rust, we have seen that there are some traps when coming from a dynamic programming language background. However, with a little bit of knowledge of referencing and basic memory management, we can avoid common pitfalls and write safe, performant code quickly that can handle errors.
In this chapter, we also covered the concepts of borrowing and referencing in Rust. While adhering to borrowing rules requires more effort than coding in a garbage-collected language, we have a deeper understanding of how variables are placed in memory. This deeper understanding is safer as we know exactly what data we point to. For example, if we were using a language like Python and created an instance of an object when we passed it into two dictionaries (Python’s version of a hash map), then if we updated one instance, the other value in the hash map would also be updated because it is a shared reference to the same memory address. The developer, however, may never know. In Rust, the borrow-checking rules make what is going on explicit. Scopes also make it explicit when a variable is dropped from memory.
We now know enough Rust to get started. In the next chapter, we will cover useful patterns for web programming and metaprogramming.