4 Lifetimes, ownership, and borrowing

This chapter covers

  • Discovering what the term lifetime means in Rust programming
  • Working with the borrow checker rather than against it
  • Multiple tactics for dealing with issues when these crop up
  • Understanding the responsibilities of an owner
  • Learning how to borrow values that are owned elsewhere

This chapter explains one of the concepts that trip up most newcomers to Rust—its borrow checker. The borrow checker checks that all access to data is legal, which allows Rust to prevent safety issues. Learning how this works will, at the very least, speed up your development time by helping you avoid run-ins with the compiler. More significantly though, learning to work with the borrow checker allows you to ...

Get Rust in Action 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.