Borrowing and References: Rust’s Version of ref (But Nicer)

Borrowing and References: Rust’s Version of ref (But Nicer)

If you’ve been writing C# for a while, you’ve likely crossed paths with ref, in, and out parameters. They allow you to pass variables by reference, enabling a method to read or modify the original value.

Useful? Definitely.

Safe? Uh… sometimes.

In Rust, there’s a similar concept called borrowing. It uses & and &mut, and it feels a lot like passing ref or in in C#, but with one significant difference:

The compiler enforces safety rules that make data races and invalid access impossible.

Today, we’re diving into borrowing, references, and how Rust holds your hand (and your memory) without letting you write foot-gun code.