Underscore

The underscore is a reserved identifier in Rust and serves different purposes depending on the context. It usually means that something is ignored.

Underscores in patterns
in a pattern is called a wildcard, because it matches anything:

The wildcard is not a variable binding, because  can't be used as a variable. Note however, if the matched type has a destructor, the destructor is run at the end of the enclosing scope.

Underscores in types
Underscores can be used to omit type declarations. For example, it can be used to specify only part of a type, and let Rust infer the rest:

Anonymous lifetime
The anonymous lifetime can be used where an explicit lifetime must be specified, even though it is used only once:

The  block above is more concise thanks to the anonymous lifetime. The  function's return type could just be written as , but the anonymous lifetime makes it clearer that the struct borrows something.

Anonymous items
items can be anonymous, by writing  instead of a name:

These aren't too useful though, since there is no way to use them at runtime. However, they can be used to evaluate something at compile time, e.g. to verify that something compiles.