What does @ mean in a match statement?

126 Views Asked by At

I've started to study the rotor library and I've found the expression:

me @ Echo::Server(..) => me.accept(),

What does this mean and how do I use the @ operator? My guess is that it is something like a cast operation, but the Rust book's section about casting doesn't mention it.

1

There are 1 best solutions below

0
On BEST ANSWER

You can use the syntax index in the Rust Book to look up bits of syntax. In this case, it's a pattern binding, used to bind a specific part of a pattern to a variable.

Here, it's being used to bind the entire value to me if and only if it is an Echo::Server variant.