O'Reilly logo

Rust Essentials by Ivo Balbaert

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Ownership and borrowing

In the previous section, the word borrowed was mentioned in most error messages. What's this all about? What is the logic behind this borrow-checker mechanism?

Every program, whatever it does, whether reading data from a database or making a computation, is concerned with handling resources. The most common resource in a program is the memory space allocated to its variables. Other resources could be files, network connections, database connections, and so on. Every resource is given a name when we make a binding to it with let; in Rust's language, we say that the resource gets an owner, for example, in the following code snippet, klaatu owns a piece of memory that is taken up by the Alien struct instance:

// see code in ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required