Rust: What does the `@` (at sign) operator do?

Viewed 656

I saw the following line in my code, and I am not sure what it does as I haven't encountered the @ operator before.

if let e@Err(_) = changed {
    ...
}

Can this line be written without the @ operator, what would that look like?

3 Answers

To answer your second question, Yes, it would look like

if let Err(_) = &changed {
    // continue to use `changed` like you would use `e`
}

Note that in order to continue to use changed inside the body, you need to match for the reference &changed. Otherwise it will be moved and discarded (unless it happens to be Copy).

Related