2 An overview of Rust
This chapter covers
- Designing systems that properly utilize Rust’s ownership system
- Visualizing Rust’s lifetime system to aid in debugging
- Controlling allocations of strings for fast performance
- Enums and basic error handling
Before we can integrate a Rust library into an existing application written in another language, we first need to understand the basics of Rust programming. This chapter guides us through a simple application to manage digital artworks for an art museum and teaches us about how the ownership system works. Ownership and borrowing are considered by many to be some of the most challenging things for new Rust developers to learn. We’re starting with them here instead of something simpler because these are the areas where Rust differs most from other programming languages, and they’re at the core of all Rust programs. If we don’t take the time to cover these important ideas now, it will make the rest of the book far more difficult. We’re going to use an example that ties the ownership and borrowing components of Rust programs to ownership and use of digital artwork. This process should make reasoning about ownership easier, and we’ll introduce tools for visualizing changes to ownership over time.