Member-only story

Memory management in Rust -Part 2: Reference borrowing

Mousse Anis
5 min readAug 23, 2022

--

In my previous article Memory management in Rust — Part 1: Ownership and Moves, we eased our way into understanding how memory is managed in Rust.

We discovered the concepts of Ownership and Moves, which can be summarized by the following sentence:

Every value has a single owner that determines its lifetime.

In this second part article, we will cover the concepts of reference and reference borrowing; We are almost at the finish line … so please hang on 🦾.

What is a Reference?

A reference is a pointer, which does not own the value it points to; It is a memory address where the value it points to is represented.

References are created by using the ampersand & , and asterisk (*) is used for dereferencing (accessing the value it refers to).

Assuming we have let variable = 1; , with let reference = &variable; , reference is a reference that points to value, and *reference is equivalent to 1 which is the value sorted within variable.

--

--

Mousse Anis
Mousse Anis

Written by Mousse Anis

Ex Quant, now software engineer who loves to cook. Opinions/Views are my own

Responses (1)