4 Introductory patterns

This chapter covers

  • Understanding resource acquisition is initialization
  • Passing arguments by value versus reference
  • Using constructors
  • Understanding object member visibility and access
  • Handling errors
  • Global state handling with lazy-static.rs, OnceCell, and static_init

Now we’re ready to dive into some more concrete patterns. We begin by reviewing some elementary topics: RAII, passing values, constructors, and visibility. Then we’ll move on to slightly more complex subjects: error handling and global variables. Although the chapter discusses many topics, it focuses on bite-size patterns, which we’ll use a lot.

This chapter also introduces crates, which are Rust libraries built by the community. The Rust language ...

Get Idiomatic Rust now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.