Rust tips is a user on octodon.social. You can follow them or interact with them if you have an account anywhere in the fediverse. If you don't, you can sign up here.
Rust tips @rust

When to use `ref` in ?

Probably only in `match` and `if let` if the borrow checker shouts at you. These are the same:

let ref x = y;
let x = &y;

`ref` is the way of saying you want to make a reference when you can only write the left side (the pattern) of the assignment.

In patterns `&` means you *expect* to see a reference, but it doesn't *make* one. These are the same:

let x = y;
let &x = &y;

Try it: is.gd/DIMRXy

· Web · 2 · 2