What is ref vs & in pattern matching

Use `ref` to create a reference from a value and `&` to match a reference and bind the underlying value.

In pattern matching, ref creates a new immutable reference to a part of the value, while & matches an existing reference and binds the value it points to.

let data = String::from("hello");

// `ref r` binds `r` to `&data` (a reference to the String)
let ref r = data;

// `&s` matches if `data` is a reference, binding `s` to the String itself
let &s = &data; 
// Note: `&s` only works if the value being matched is already a reference.

Use ref when you have the value and want a reference to a sub-part. Use & when you have a reference and want to match the value inside it.