pub struct Block {
pub stmts: Vec<Stmt>,
pub expr: Option<Box<Expr>>,
pub span: Span,
}Expand description
A block of statements with an optional trailing expression.
Blocks are the body of functions, loops, and if-branches. The optional
trailing expr is the block’s value when used as an expression
(e.g., { let x = 1; x + 1 } evaluates to the trailing expression).
Fields§
§stmts: Vec<Stmt>Ordered list of statements in the block.
expr: Option<Box<Expr>>Optional trailing expression (the block’s value).
span: SpanSource span of the entire block including braces.
Implementations§
Source§impl Block
impl Block
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Return true if the block has no statements and no trailing expression.
An empty block {} contributes nothing to the program and may be
flagged as a warning by the validator.
Sourcepub fn stmt_count(&self) -> usize
pub fn stmt_count(&self) -> usize
Return the number of statements in this block.
Does not count the trailing expression (if any). Use
has_trailing_expr to check for that separately.
Sourcepub fn has_trailing_expr(&self) -> bool
pub fn has_trailing_expr(&self) -> bool
Return true if the block has a trailing expression.
A trailing expression (the final expression without a semicolon) determines the block’s value when used in expression position.