This appendix contains a glossary of Rust’s syntax, including operators and other symbols that appear by themselves or in the context of paths, generics, trait bounds, macros, attributes, comments, tuples, and brackets.
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.
|Bitwise or logical complement|
|Arithmetic remainder and assignment|
|Borrowed pointer type|
|Bitwise AND and assignment|
|Short-circuiting logical AND|
|Arithmetic multiplication and assignment|
|Compound type constraint|
|Arithmetic addition and assignment|
|Argument and element separator|
|Arithmetic subtraction and assignment|
|Function and closure return type|
|Right-exclusive range literal|
|Right-inclusive range literal|
|Struct literal update syntax|
|“And the rest” pattern binding|
|In a pattern: inclusive range pattern|
|Arithmetic division and assignment|
|Struct field initializer|
|Statement and item terminator|
|Part of fixed-size array syntax|
|Left-shift and assignment|
|Less than comparison|
|Less than or equal to comparison|
|Part of match arm syntax|
|Greater than comparison|
|Greater than or equal to comparison|
|Right-shift and assignment|
|Bitwise exclusive OR|
|Bitwise exclusive OR and assignment|
|Bitwise OR and assignment|
|Short-circuiting logical OR|
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.
|Named lifetime or loop label|
|Numeric literal of specific type|
|Raw string literal, escape characters not processed|
|Byte string literal; constructs a |
|Raw byte string literal, combination of raw and byte string literal|
|ASCII byte literal|
|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.
|Path relative to the crate root (i.e., an explicitly absolute path)|
|Path relative to the current module (i.e., an explicitly relative path).|
|Path relative to the parent of the current module|
|Associated constants, functions, and types|
|Associated item for a type that cannot be directly named (e.g., |
|Disambiguating a method call by naming the trait that defines it|
|Disambiguating a method call by naming the type for which it’s defined|
|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.
|Specifies parameters to generic type in a type (e.g., |
|Specifies parameters to generic type, function, or method in an expression; often referred to as turbofish (e.g., |
|Define generic function|
|Define generic structure|
|Define generic enumeration|
|Define generic implementation|
|Higher-ranked lifetime bounds|
|A generic type where one or more associated types have specific assignments (e.g., |
Table B-5 shows symbols that appear in the context of constraining generic type parameters with trait bounds.
|Generic parameter |
|Generic type |
|Generic type |
|Generic lifetime |
|Allow generic type parameter to be a dynamically sized type|
|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-7 shows symbols that create comments.
|Inner line doc comment|
|Outer line doc comment|
|Inner block doc comment|
|Outer block doc comment|
Table B-8 shows symbols that appear in the context of using tuples.
|Empty tuple (aka unit), both literal and type|
|Single-element tuple expression|
|Single-element tuple type|
|Function call expression; also used to initialize tuple |
Table B-9 shows the contexts in which curly braces are used.
Table B-10 shows the contexts in which square brackets are used.
|Array literal containing |
|Array type containing |
|Collection indexing. Overloadable (|
|Collection indexing pretending to be collection slicing, using |