© Carlo Milanesi 2018
Carlo MilanesiBeginning Rusthttps://doi.org/10.1007/978-1-4842-3468-6_22

22. Borrowing and Lifetimes

Carlo Milanesi1 
(1)
Bergamo, Italy
 
In this chapter, you will learn:
  • The concepts of “borrowing” and “lifetime”

  • Which are the typical programming errors regarding borrowing, that plague system software

  • How Rust strict syntax can prevent such typical errors, using a borrow checker

  • How inserting a block can restrict the scope of borrowing

  • Why functions returning references need lifetime specifiers

  • How to use lifetime specifiers for functions, and what they mean

  • What is the task of the borrow checker

Ownership and Borrowing

We already saw that when you assign a variable "a" to a variable "b", there are two cases: either their type is copyable, ...

Get Beginning Rust: From Novice to Professional 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.