6. Syntax Index
Syntax Index
Keywords
-
as
: primitive casting, or disambiguating the specific trait containing an item. See Casting Between Types (as
), Universal Function Call Syntax (Angle-bracket Form), Associated Types. -
break
: break out of loop. See Loops (Ending Iteration Early). -
const
: constant items and constant raw pointers. Seeconst
andstatic
, Raw Pointers. -
continue
: continue to next loop iteration. See Loops (Ending Iteration Early). -
crate
: external crate linkage. See Crates and Modules (Importing External Crates). -
else
: fallback forif
andif let
constructs. Seeif
,if let
. -
enum
: defining enumeration. See Enums. -
extern
: external crate, function, and variable linkage. See Crates and Modules (Importing External Crates), Foreign Function Interface- -
false
: boolean false literal- See Primitive Types (Booleans). -
fn
: function definition and function pointer types. See Functions. -
for
: iterator loop, part of traitimpl
syntax, and higher-ranked lifetime syntax. See Loops (for
), Method Syntax. -
if
: conditional branching. Seeif
,if let
. -
impl
: inherent and trait implementation blocks. See Method Syntax. -
in
: part offor
loop syntax. See Loops (for
). -
let
: variable binding. See Variable Bindings. -
loop
: unconditional, infinite loop. See Loops (loop
). -
match
: pattern matching. See Match. -
mod
: module declaration. See Crates and Modules (Defining Modules). -
move
: part of closure syntax. See Closures (move
closures). -
mut
: denotes mutability in pointer types and pattern bindings. See Mutability. -
pub
: denotes public visibility instruct
fields,impl
blocks, and modules. See Crates and Modules (Exporting a Public Interface). -
ref
: by-reference binding. See Patterns (ref
andref mut
). -
return
: return from function. See Functions (Early Returns). -
Self
: implementor type alias. See Traits. -
self
: method subject. See Method Syntax (Method Calls). -
static
: global variable. Seeconst
andstatic
(static
). -
struct
: structure definition. See Structs. -
trait
: trait definition. See Traits. -
true
: boolean true literal. See Primitive Types (Booleans). -
type
: type alias, and associated type definition. Seetype
Aliases, Associated Types. -
unsafe
: denotes unsafe code, functions, traits, and implementations. See Unsafe. -
use
: import symbols into scope. See Crates and Modules (Importing Modules withuse
). -
where
: type constraint clauses. See Traits (where
clause). -
while
: conditional loop. See Loops (while
).
Operators and Symbols
-
!
(ident!(…)
,ident!{…}
,ident![…]
): denotes macro expansion. See Macros. -
!
(!expr
): bitwise or logical complement. Overloadable (Not
). -
!=
(var != expr
): nonequality comparison. Overloadable (PartialEq
). -
%
(expr % expr
): arithmetic remainder. Overloadable (Rem
). -
%=
(var %= expr
): arithmetic remainder & assignment. Overloadable (RemAssign
). -
&
(expr & expr
): bitwise and. Overloadable (BitAnd
). -
&
(&expr
,&mut expr
): borrow. See References and Borrowing. -
&
(&type
,&mut type
,&'a type
,&'a mut type
): borrowed pointer type. See References and Borrowing. -
&=
(var &= expr
): bitwise and & assignment. Overloadable (BitAndAssign
). -
&&
(expr && expr
): logical and. -
*
(expr * expr
): arithmetic multiplication. Overloadable (Mul
). -
*
(*expr
): dereference. -
*
(*const type
,*mut type
): raw pointer. See Raw Pointers. -
*=
(var *= expr
): arithmetic multiplication & assignment. Overloadable (MulAssign
). -
+
(expr + expr
): arithmetic addition. Overloadable (Add
). -
+
(trait + trait
,'a + trait
): compound type constraint. See Traits (Multiple Trait Bounds). -
+=
(var += expr
): arithmetic addition & assignment. Overloadable (AddAssign
). -
,
: argument and element separator. See Attributes, Functions, Structs, Generics, Match, Closures, Crates and Modules (Importing Modules withuse
). -
-
(expr - expr
): arithmetic subtraction. Overloadable (Sub
). -
-
(- expr
): arithmetic negation. Overloadable (Neg
). -
-=
(var -= expr
): arithmetic subtraction & assignment. Overloadable (SubAssign
). -
->
(fn(…) -> type
,|…| -> type
): function and closure return type. See Functions, Closures. -
.
(expr.ident
): member access. See Structs, Method Syntax. -
..
(..
,expr..
,..expr
,expr..expr
): right-exclusive range literal. -
..
(..expr
): struct literal update syntax. See Structs (Update syntax). -
..
(variant(x, ..)
,struct_type { x, .. }
): "and the rest" pattern binding. See Patterns (Ignoring bindings). -
...
(...expr
,expr...expr
) in an expression: inclusive range expression. See Iterators. -
...
(expr...expr
) in a pattern: inclusive range pattern. See Patterns (Ranges). -
/
(expr / expr
): arithmetic division. Overloadable (Div
). -
/=
(var /= expr
): arithmetic division & assignment. Overloadable (DivAssign
). -
:
(pat: type
,ident: type
): constraints. See Variable Bindings, Functions, Structs, Traits. -
:
(ident: expr
): struct field initializer. See Structs. -
:
('a: loop {…}
): loop label. See Loops (Loops Labels). -
;
: statement and item terminator. -
;
([…; len]
): part of fixed-size array syntax. See Primitive Types (Arrays). -
<<
(expr << expr
): left-shift. Overloadable (Shl
). -
<<=
(var <<= expr
): left-shift & assignment. Overloadable (ShlAssign
). -
<
(expr < expr
): less-than comparison. Overloadable (PartialOrd
). -
<=
(var <= expr
): less-than or equal-to comparison. Overloadable (PartialOrd
). -
=
(var = expr
,ident = type
): assignment/equivalence. See Variable Bindings,type
Aliases, generic parameter defaults. -
==
(var == expr
): equality comparison. Overloadable (PartialEq
). -
=>
(pat => expr
): part of match arm syntax. See Match. -
>
(expr > expr
): greater-than comparison. Overloadable (PartialOrd
). -
>=
(var >= expr
): greater-than or equal-to comparison. Overloadable (PartialOrd
). -
>>
(expr >> expr
): right-shift. Overloadable (Shr
). -
>>=
(var >>= expr
): right-shift & assignment. Overloadable (ShrAssign
). -
@
(ident @ pat
): pattern binding. See Patterns (Bindings). -
^
(expr ^ expr
): bitwise exclusive or. Overloadable (BitXor
). -
^=
(var ^= expr
): bitwise exclusive or & assignment. Overloadable (BitXorAssign
). -
|
(expr | expr
): bitwise or. Overloadable (BitOr
). -
|
(pat | pat
): pattern alternatives. See Patterns (Multiple patterns). -
|
(|…| expr
): closures. See Closures. -
|=
(var |= expr
): bitwise or & assignment. Overloadable (BitOrAssign
). -
||
(expr || expr
): logical or. -
_
: "ignored" pattern binding (see Patterns (Ignoring bindings)). Also used to make integer-literals readable (see Reference (Integer literals)). -
?
(expr?
): Error propagation. Returns early whenErr(_)
is encountered, unwraps otherwise. Similar to thetry!
macro.
Other Syntax
-
'ident
: named lifetime or loop label. See Lifetimes, Loops (Loops Labels). -
…u8
,…i32
,…f64
,…usize
, …: numeric literal of specific type. -
"…"
: string literal. See Strings. -
r"…"
,r#"…"#
,r##"…"##
, …: raw string literal, escape characters are not processed. See Reference (Raw String Literals). -
b"…"
: byte string literal, constructs a[u8]
instead of a string. See Reference (Byte String Literals). -
br"…"
,br#"…"#
,br##"…"##
, …: raw byte string literal, combination of raw and byte string literal. See Reference (Raw Byte String Literals). -
'…'
: character literal. See Primitive Types (char
). -
b'…'
: ASCII byte literal. -
|…| expr
: closure. See Closures.
-
ident::ident
: path. See Crates and Modules (Defining Modules). -
::path
: path relative to the crate root (i.e. an explicitly absolute path). See Crates and Modules (Re-exporting withpub use
). -
self::path
: path relative to the current module (i.e. an explicitly relative path). See Crates and Modules (Re-exporting withpub use
). -
super::path
: path relative to the parent of the current module. See Crates and Modules (Re-exporting withpub use
). -
type::ident
,<type as trait>::ident
: associated constants, functions, and types. See Associated Types. -
<type>::…
: associated item for a type which cannot be directly named (e.g.<&T>::…
,<[T]>::…
, etc.). See Associated Types. -
trait::method(…)
: disambiguating a method call by naming the trait which defines it. See Universal Function Call Syntax. -
type::method(…)
: disambiguating a method call by naming the type for which it's defined. See Universal Function Call Syntax. -
<type as trait>::method(…)
: disambiguating a method call by naming the trait and type. See Universal Function Call Syntax (Angle-bracket Form).
-
path<…>
(e.g.Vec<u8>
): specifies parameters to generic type in a type. See Generics. -
path::<…>
,method::<…>
(e.g."42".parse::<i32>()
): specifies parameters to generic type, function, or method in an expression. See Generics § Resolving ambiguities. -
fn ident<…> …
: define generic function. See Generics. -
struct ident<…> …
: define generic structure. See Generics. -
enum ident<…> …
: define generic enumeration. See Generics. -
impl<…> …
: define generic implementation. -
for<…> type
: higher-ranked lifetime bounds. -
type<ident=type>
(e.g.Iterator<Item=T>
): a generic type where one or more associated types have specific assignments. See Associated Types.
-
T: U
: generic parameterT
constrained to types that implementU
. See Traits. -
T: 'a
: generic typeT
must outlive lifetime'a
. When we say that a type 'outlives' the lifetime, we mean that it cannot transitively contain any references with lifetimes shorter than'a
. -
T : 'static
: The generic typeT
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. See Unsized Types (?Sized
). -
'a + trait
,trait + trait
: compound type constraint. See Traits (Multiple Trait Bounds).
-
#[meta]
: outer attribute. See Attributes. -
#![meta]
: inner attribute. See Attributes. -
$ident
: macro substitution. See Macros. -
$ident:kind
: macro capture. See Macros. -
$(…)…
: macro repetition. See Macros.
-
//
: line comment. See Comments. -
//!
: inner line doc comment. See Comments. -
///
: outer line doc comment. See Comments. -
/*…*/
: block comment. See Comments. -
/*!…*/
: inner block doc comment. See Comments. -
/**…*/
: outer block doc comment. See Comments.
-
!
: always empty Never type. See Diverging Functions.
-
()
: empty tuple (a.k.a. unit), both literal and type. -
(expr)
: parenthesized expression. -
(expr,)
: single-element tuple expression. See Primitive Types (Tuples). -
(type,)
: single-element tuple type. See Primitive Types (Tuples). -
(expr, …)
: tuple expression. See Primitive Types (Tuples). -
(type, …)
: tuple type. See Primitive Types (Tuples). -
expr(expr, …)
: function call expression. Also used to initialize tuplestruct
s and tupleenum
variants. See Functions. -
ident!(…)
,ident!{…}
,ident![…]
: macro invocation. See Macros. -
expr.0
,expr.1
, …: tuple indexing. See Primitive Types (Tuple Indexing).
-
{…}
: block expression. -
Type {…}
:struct
literal. See Structs.
-
[…]
: array literal. See Primitive Types (Arrays). -
[expr; len]
: array literal containinglen
copies ofexpr
. See Primitive Types (Arrays). -
[type; len]
: array type containinglen
instances oftype
. See Primitive Types (Arrays). -
expr[expr]
: collection indexing. Overloadable (Index
,IndexMut
). -
expr[..]
,expr[a..]
,expr[..b]
,expr[a..b]
: collection indexing pretending to be collection slicing, usingRange
,RangeFrom
,RangeTo
,RangeFull
as the "index".
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/book/first-edition/syntax-index.html