This appendix provides an index of tokens and common forms with links to where those elements are defined.
| Comment | Use |
|---|---|
// |
[line comment][comments] |
//! |
[inner line comment][comments] |
/// |
[outer line doc comment][comments] |
/*…*/ |
[block comment][comments] |
/*!…*/ |
[inner block doc comment][comments] |
/**…*/ |
[outer block doc comment][comments] |
| Token | Use |
|---|---|
ident |
identifiers |
r#ident |
raw identifiers |
'ident |
lifetimes and loop labels |
'r#ident |
raw lifetimes and loop labels |
…u8, …i32, …f64, …usize, … |
number literals |
"…" |
string literals |
r"…", r#"…"#, r##"…"##, … |
raw string literals |
b"…" |
byte string literals |
br"…", br#"…"#, br##"…"##, … |
raw byte string literals |
'…' |
character literals |
b'…' |
byte literals |
c"…" |
C string literals |
cr"…", cr#"…"#, cr##"…"##, … |
raw C string literals |
| Syntax | Use |
|---|---|
ident!(…)ident! {…}ident![…] |
macro invocations |
$ident |
macro metavariable |
$ident:kind |
macro matcher fragment specifier |
$(…)… |
macro repetition |
| Syntax | Use |
|---|---|
#[meta] |
outer attribute |
#![meta] |
inner attribute |
[Items] are the components of a crate.
| Item | Use |
|---|---|
mod ident;mod ident {…} |
modules |
use path; |
use declarations |
fn ident(…) {…} |
functions |
type Type = Type; |
type aliases |
struct ident {…} |
structs |
enum ident {…} |
enumerations |
union ident {…} |
unions |
trait ident {…} |
traits |
impl Type {…}impl Type for Trait {…} |
implementations |
const ident = expr; |
constant items |
static ident = expr; |
static items |
extern "C" {…} |
external blocks |
fn ident<…>(…) …struct ident<…> {…}enum ident<…> {…}impl<…> Type<…> {…} |
generic definitions |
Type expressions are used to refer to types.
| Type | Use |
|---|---|
bool, u8, f64, str, … |
primitive types |
for<…> |
higher-ranked trait bounds |
T: TraitA + TraitB |
trait bounds |
T: 'a + 'b |
lifetime bounds |
T: TraitA + 'a |
trait and lifetime bounds |
T: ?Sized |
relaxed trait bounds |
[Type; len] |
array types |
(Type, …) |
tuple types |
[Type] |
slice types |
(Type) |
parenthesized types |
impl Trait |
impl trait types, anonymous type parameters |
dyn Trait |
trait object types |
identident::… |
type paths (can refer to structs, enumerations, unions, type aliases, traits, generics, etc.) |
Type<…>Trait<…> |
generic arguments (e.g. Vec<u8>) |
Trait<ident = Type> |
associated type bindings (e.g. Iterator<Item = T>) |
Trait<ident: …> |
associated type bounds (e.g. Iterator<Item: Send>) |
&Type&mut Type |
reference types |
*mut Type*const Type |
raw pointer types |
fn(…) -> Type |
function pointer types |
_ |
inferred type, inferred const |
'_ |
placeholder lifetime |
! |
never type |
[Patterns] are used to match values.
| Pattern | Use |
|---|---|
"foo", 'a', 123, 2.4, … |
literal patterns |
ident |
identifier patterns |
_ |
wildcard pattern |
.. |
rest pattern |
a.., ..b, a..b, a..=b, ..=b |
range patterns |
&pattern&mut pattern |
reference patterns |
path {…} |
struct patterns |
path(…) |
tuple struct patterns |
(pattern, …) |
tuple patterns |
(pattern) |
grouped patterns |
[pattern, …] |
slice patterns |
CONST, Enum::Variant, … |
path patterns |