pub enum Statement {
    SingleStatement(Expression),
    AssignStatement(IdentifierExpression),
    IndexAssignStatement {
        table: Expression,
        index: Expression,
        value: Expression,
    },
    ReturnStatement(Option<Expression>),
    WhileStatement {
        condition: Expression,
        body: Vec<Statement>,
    },
    IfStatement {
        condition: Expression,
        body: Vec<Statement>,
        else_body: Option<Vec<Statement>>,
    },
}
Expand description

Statement in a function

Variants

SingleStatement(Expression)

A single expression as a statement

Example:
f(x + 1, z, true)

AssignStatement(IdentifierExpression)

Assignment to an identifier from the result of an expression

Example:
y = (x + 1) * 2

IndexAssignStatement

Fields

table: Expression

Destination container to put value into

index: Expression

Index or key into table

value: Expression

Expression to assign from

Assignment to an indexed slot in a container

Example:
items[i - 1] = g(x) + 9

ReturnStatement(Option<Expression>)

Return statement with an optional expression

Example:
return

or

return x * 2

WhileStatement

Fields

condition: Expression

Conditional expression to determine if iteration should continue

body: Vec<Statement>

Statement body of the loop

While loop

Example:
while a < b do
  b = b - f(a)
end

IfStatement

Fields

condition: Expression

Conditional expression to determine if the if clause should run

body: Vec<Statement>

Statement body of the if clause

else_body: Option<Vec<Statement>>

Optional statement body of the else clause

If (else) statement

If statements can have zero or more elseif clauses after the if clause and an optional else clause at the end.

Example:
if x >= 5 then
  f(x)
end

or

if x == 9 then
  f(x)
elseif x == 7 then
  g(x)
elseif x <= 0 then
  h(0)
else
  h(x)
end

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.