rust-journey-borrow-is-not-pointer

Borrow is not a pointer

Rust and its way to manage variables in the memory is very different from others languages like C++ for instance. And often, the borrow checker mechanism and its representation in memory is explained as it is a pointer. In many ways it looks similar and this comparaison can help understanding things.
But as explained in an awesome way in this article, Borrow is not a pointer.

I extracted few key sentences below, but go and read that article to understand the difference between borrow and a pointer:

Author : Bartłomiej Kuras
Article: Borrow is not a pointer

“A pointer is a variable containing an address of some data in the memory

One standard operation on pointers is the dereference, which reaches the memory addressed by the pointer and retrieves data from it

the Rust reference cannot be built from an arbitrary integer value. The only way to create a reference in safe Rust is to borrow it from some existing variable. The reference will then refer to this variable. A significant thing to emphasize is that the borrower will refer to this variable, not point to memory

the pointers to two distinct objects have to be different. As a result, even objects with no payload have to occupy at least one byte of memory. There is no such thing in Rust. In Rust, every object can be borrowed, but borrow doesn’t have to be an address”

Total
0
Share