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...
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...
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...
Patterns Pattern -> `|`? PatternNoTopAlt ( `|` PatternNoTopAlt )* PatternNoTopAlt -> PatternWithoutModernRange | ModernRangePattern PatternWithoutModernRange -> LiteralPattern | IdentifierPattern | WildcardPattern | RestPattern | ReferenceP...
_ 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...
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...
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...
match expressions MatchExpression -> `match` Scrutinee `{` InnerAttribute* MatchArms? `}` Scrutinee -> Expression _except [StructExpression]_ MatchArms -> ( MatchArm `=>` ( ExpressionWithoutBlock `,` | ExpressionWithBlock `,`? ) )* MatchArm...
if expressions IfExpression -> `if` Conditions BlockExpressionNoInnerAttributes (`else` ( BlockExpressionNoInnerAttributes | IfExpression ) )? Conditions -> Expression _except [StructExpression]_ | LetChain LetChain -> LetChainCondition ( `...
Range expressions RangeExpression -> RangeExpr | RangeFromExpr | RangeToExpr | RangeFullExpr | RangeInclusiveExpr | RangeToInclusiveExpr RangeExpr -> Expression `..` Expression RangeFromExpr -> Expression `..` RangeToExpr -> `..` Expression...
Loops and other breakable expressions LoopExpression -> LoopLabel? ( InfiniteLoopExpression | PredicateLoopExpression | IteratorLoopExpression | LabelBlockExpression ) Rust supports four loop expressions: • A loop expression denotes an infi...
Closure expressions ClosureExpression -> `async`?[^cl-async-edition] `move`? ( `||` | `|` ClosureParameters? `|` ) (Expression | `->` TypeNoBounds BlockExpression) ClosureParameters -> ClosureParam (`,` ClosureParam)* `,`? ClosureParam -> O...
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...
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...
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...
Struct expressions StructExpression -> PathInExpression `{` (StructExprFields | StructBase)? `}` StructExprFields -> StructExprField (`,` StructExprField)* (`,` StructBase | `,`?) StructExprField -> OuterAttribute* ( IDENTIFIER | (IDENTIFIE...
Tuple and tuple indexing expressions Tuple expressions TupleExpression -> `(` TupleElements? `)` TupleElements -> ( Expression `,` )+ Expression? A tuple expression constructs tuple values. The syntax for tuple expressions is a parenthesize...
Array and array index expressions Array expressions ArrayExpression -> `[` ArrayElements? `]` ArrayElements -> Expression ( `,` Expression )* `,`? | Expression `;` Expression Array expressions construct arrays. Array expressions come in two...
Grouped expressions GroupedExpression -> `(` Expression `)` A parenthesized expression wraps a single expression, evaluating to that expression. The syntax for a parenthesized expression is a (, then an expression, called the enclosed opera...