Struct expressions StructExpression -> PathInExpression `{` (StructExprFields | StructBase)? `}` StructExprFields -> StructExprField (`,` StructExprField)* (`,` StructBase | `,`?) StructExprField -> OuterAttribute* ( IDENTIFIER | (IDENTIFIE...
Call expressions CallExpression -> Expression `(` CallParams? `)` CallParams -> Expression ( `,` Expression )* `,`? A call expression calls a function. The syntax of a call expression is an expression, called the function operand, followed...
Method-call expressions MethodCallExpression -> Expression `.` PathExprSegment `(`CallParams? `)` A method call consists of an expression (the receiver) followed by a single dot, an expression path segment, and a parenthesized expression-li...
Field access expressions FieldExpression -> Expression `.` IDENTIFIER A field expression is a place expression that evaluates to the location of a field of a struct or union. When the operand is mutable, the field expression is also mutable...
Closure expressions ClosureExpression -> `async`?[^cl-async-edition] `move`? ( `||` | `|` ClosureParameters? `|` ) (Expression | `->` TypeNoBounds BlockExpression) ClosureParameters -> ClosureParam (`,` ClosureParam)* `,`? ClosureParam -> O...
Loops and other breakable expressions LoopExpression -> LoopLabel? ( InfiniteLoopExpression | PredicateLoopExpression | IteratorLoopExpression | LabelBlockExpression ) Rust supports four loop expressions: • A loop expression denotes an infi...
Range expressions RangeExpression -> RangeExpr | RangeFromExpr | RangeToExpr | RangeFullExpr | RangeInclusiveExpr | RangeToInclusiveExpr RangeExpr -> Expression `..` Expression RangeFromExpr -> Expression `..` RangeToExpr -> `..` Expression...
if expressions IfExpression -> `if` Conditions BlockExpressionNoInnerAttributes (`else` ( BlockExpressionNoInnerAttributes | IfExpression ) )? Conditions -> Expression _except [StructExpression]_ | LetChain LetChain -> LetChainCondition ( `...
match expressions MatchExpression -> `match` Scrutinee `{` InnerAttribute* MatchArms? `}` Scrutinee -> Expression _except [StructExpression]_ MatchArms -> ( MatchArm `=>` ( ExpressionWithoutBlock `,` | ExpressionWithBlock `,`? ) )* MatchArm...
return expressions ReturnExpression -> `return` Expression? Return expressions are denoted with the keyword return. Evaluating a return expression moves its argument into the designated output location for the current function call, destroy...
Await expressions AwaitExpression -> Expression `.` `await` An await expression is a syntactic construct for suspending a computation provided by an implementation of std::future::IntoFuture until the given future is ready to produce a valu...
_ expressions UnderscoreExpression -> `_` Underscore expressions, denoted with the symbol _, are used to signify a placeholder in a destructuring assignment. They may only appear in the left-hand side of an assignment. Note that this is dis...
Patterns Pattern -> `|`? PatternNoTopAlt ( `|` PatternNoTopAlt )* PatternNoTopAlt -> PatternWithoutModernRange | ModernRangePattern PatternWithoutModernRange -> LiteralPattern | IdentifierPattern | WildcardPattern | RestPattern | ReferenceP...
Types Every variable, item, and value in a Rust program has a type. The type of a value defines the interpretation of the memory holding it and the operations that may be performed on the value. Built-in types are tightly integrated into th...
Boolean type let b: bool = true; The boolean type or bool is a primitive data type that can take on one of two values, called true and false. Values of this type may be created using a literal expression using the keywords true and false co...
Numeric types Integer types The unsigned integer types consist of: Type | Minimum | Maximum -------|---------|------------------- u8 | 0 | 28-1 u16 | 0 | 216-1 u32 | 0 | 232-1 u64 | 0 | 264-1 u128 | 0 | 2128-1 The signed two's complement in...
Character type The char type represents a single Unicode scalar value (i.e., a code point that is not a surrogate). [!EXAMPLE] let c: char = 'a'; let emoji: char = '😀'; let unicode: char = '\u{1F600}'; [!NOTE] See [the standard library docs...
String slice type The string slice (str) type represents a sequence of characters. let greeting1: &str = "Hello, world!"; let greeting2: &str = "你好,世界"; [!NOTE] See [the standard library docs][str] for information on the impls of the str ty...
Never type NeverType -> `!` The never type ! is a type with no values, representing the result of computations that never complete. Expressions of type ! can be coerced into any other type. The ! type can only appear in function return type...