Table B-1 contains the operators in Rust, an example of how the operator would appear in context, a short explanation, and whether that operator is overloadable. If an operator is overloadable, the relevant trait to use to overload that operator is listed.
Table B-1: Operators
Non-operator Symbols
The following list contains all non-letters that don’t function as operators; that is, they don’t behave like a function or method call.
Table B-2 shows symbols that appear on their own and are valid in a variety of locations.
Table B-2: Stand-Alone Syntax
Symbol | Explanation |
---|---|
‘ident | Named lifetime or loop label |
…u8 , …i32 , …f64 , …usize , etc. | Numeric literal of specific type |
“…” | String literal |
r”…” , r#”…”# , r##”…”## , etc. | Raw string literal, escape characters not processed |
b”…” | Byte string literal; constructs a [u8] instead of a string |
br”…” , br#”…”# , br##”…”## , etc. | Raw byte string literal, combination of raw and byte string literal |
‘…’ | Character literal |
b’…’ | ASCII byte literal |
|…| expr | Closure |
! | Always empty bottom type for diverging functions |
“Ignored” pattern binding; also used to make integer literals readable |
Table B-3 shows symbols that appear in the context of a path through the module hierarchy to an item.
Symbol | Explanation |
---|---|
ident::ident | Namespace path |
::path | Path relative to the crate root (i.e., an explicitly absolute path) |
self::path | Path relative to the current module (i.e., an explicitly relative path). |
super::path | Path relative to the parent of the current module |
type::ident , <type as trait>::ident | Associated constants, functions, and types |
<type>::… | Associated item for a type that cannot be directly named (e.g., <&T>::… , <[T]>::… , etc.) |
trait::method(…) | Disambiguating a method call by naming the trait that defines it |
type::method(…) | Disambiguating a method call by naming the type for which it’s defined |
<type as trait>::method(…) | Disambiguating a method call by naming the trait and type |
Table B-4 shows symbols that appear in the context of using generic type parameters.
Table B-4: Generics
Table B-5 shows symbols that appear in the context of constraining generic type parameters with trait bounds.
Table B-5: Trait Bound Constraints
Symbol | Explanation |
---|---|
T: U | Generic parameter T constrained to types that implement U |
T: ‘a | Generic type T must outlive lifetime ‘a (meaning the type cannot transitively contain any references with lifetimes shorter than ‘a ) |
T : ‘static | Generic type T contains no borrowed references other than ‘static ones |
‘b: ‘a | Generic lifetime ‘b must outlive lifetime ‘a |
T: ?Sized | Allow generic type parameter to be a dynamically sized type |
‘a + trait , trait + trait | Compound type constraint |
Table B-6 shows symbols that appear in the context of calling or defining macros and specifying attributes on an item.
Table B-6: Macros and Attributes
Symbol | Explanation |
---|---|
#[meta] | Outer attribute |
#![meta] | Inner attribute |
$ident | Macro substitution |
$ident:kind | Macro capture |
$(…)… | Macro repetition |
ident!(…) , ident!{…} , ident![…] | Macro invocation |
Table B-7: Comments
Table B-8 shows symbols that appear in the context of using tuples.
Table B-8: Tuples
Symbol | Explanation |
---|---|
() | Empty tuple (aka unit), both literal and type |
(expr) | Parenthesized expression |
(expr,) | Single-element tuple expression |
(type,) | Single-element tuple type |
(expr, …) | Tuple expression |
(type, …) | Tuple type |
expr(expr, …) | Function call expression; also used to initialize tuple struct s and tuple enum variants |
expr.0 , expr.1 , etc. | Tuple indexing |
Table B-9 shows the contexts in which curly braces are used.
Table B-9: Curly Brackets
Context | Explanation |
---|---|
{…} | Block expression |
Type {…} | struct literal |
Table B-10 shows the contexts in which square brackets are used.