O'Reilly logo

Mastering Rust by Vesa Kaihlavirta

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

Chapter 6 - Memory, Lifetimes, and Borrowing

Rust's compiler is based on the compiler framework LLVM. The compiler emits LLVM IR codes, which LLVM translates into an executable binary. All that typically happens transparently, but it's possible to read into the intermediate IR codes and also Assembler code if a programmer wants to dive deep.

Local variables are stored in the stack. These values have strictly limited lifetimes: values in the stack do not outlive their blocks. Values that are expected to live longer than their blocks are stored in the heap.

Rust is a safe language due to the lack of null pointers and due to the ownership, borrowing, and lifetimes memory handling system.

Regarding ownership, Rust values have either move or copy ...

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