Enum rhai::Stmt

source ·
#[non_exhaustive]
pub enum Stmt {
Show 17 variants Noop(Position), If(Box<FlowControl>, Position), Switch(Box<(Expr, SwitchCasesCollection)>, Position), While(Box<FlowControl>, Position), Do(Box<FlowControl>, ASTFlags, Position), For(Box<(Ident, Ident, FlowControl)>, Position), Var(Box<(Ident, Expr, Option<NonZeroUsize>)>, ASTFlags, Position), Assignment(Box<(OpAssignment, BinaryExpr)>), FnCall(Box<FnCallExpr>, Position), Block(Box<StmtBlock>), TryCatch(Box<FlowControl>, Position), Expr(Box<Expr>), BreakLoop(Option<Box<Expr>>, ASTFlags, Position), Return(Option<Box<Expr>>, ASTFlags, Position), Import(Box<(Expr, Ident)>, Position), Export(Box<(Ident, Ident)>, Position), Share(Box<SmallVec<[(ImmutableString, Option<NonZeroUsize>, Position); 5]>>),
}
Expand description

(internals) A statement. Exported under the internals feature only.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Noop(Position)

No-op.

§

If(Box<FlowControl>, Position)

if expr { stmt } else { stmt }

§

Switch(Box<(Expr, SwitchCasesCollection)>, Position)

switch expr { literal or range or _ if condition => stmt ,}

Data Structure
  1. Hash table for (condition, block)
  2. Default block
  3. List of ranges: (start, end, inclusive, condition, statement)
§

While(Box<FlowControl>, Position)

while expr { stmt } | loop { stmt }

If the guard expression is UNIT, then it is a loop statement.

§

Do(Box<FlowControl>, ASTFlags, Position)

do { stmt } while|until expr

Flags
§

For(Box<(Ident, Ident, FlowControl)>, Position)

for ( id , counter ) in expr { stmt }

§

Var(Box<(Ident, Expr, Option<NonZeroUsize>)>, ASTFlags, Position)

[export] let|const id = expr

Flags
§

Assignment(Box<(OpAssignment, BinaryExpr)>)

expr op= expr

§

FnCall(Box<FnCallExpr>, Position)

func ( expr ,)

This is a duplicate of Expr::FnCall to cover the very common pattern of a single function call forming one statement.

§

Block(Box<StmtBlock>)

{ stmt;}

§

TryCatch(Box<FlowControl>, Position)

try { stmt; … } catch ( var ) { stmt; … }

§

Expr(Box<Expr>)

§

BreakLoop(Option<Box<Expr>>, ASTFlags, Position)

continue/break expr

Flags
§

Return(Option<Box<Expr>>, ASTFlags, Position)

return/throw expr

Flags
§

Import(Box<(Expr, Ident)>, Position)

import expr as alias

Not available under no_module.

§

Export(Box<(Ident, Ident)>, Position)

export var as alias

Not available under no_module.

§

Share(Box<SmallVec<[(ImmutableString, Option<NonZeroUsize>, Position); 5]>>)

Convert a list of variables to shared.

Not available under no_closure.

Notes

This variant does not map to any language structure. It is currently only used only to convert normal variables into shared variables when they are captured by a closure.

Implementations§

source§

impl Stmt

source

pub const fn is_noop(&self) -> bool

Is this statement Noop?

source

pub const fn options(&self) -> ASTFlags

Get the options of this statement.

source

pub fn position(&self) -> Position

Get the position of this statement.

source

pub fn set_position(&mut self, new_pos: Position) -> &mut Self

Override the position of this statement.

source

pub const fn returns_value(&self) -> bool

Does this statement return a value?

source

pub const fn is_self_terminated(&self) -> bool

Is this statement self-terminated (i.e. no need for a semicolon terminator)?

source

pub fn is_pure(&self) -> bool

Is this statement pure?

A pure statement has no side effects.

source

pub fn is_block_dependent(&self) -> bool

Does this statement’s behavior depend on its containing block?

A statement that depends on its containing block behaves differently when promoted to an upper block.

Currently only variable definitions (i.e. let and const), import/export statements, and eval calls (which may in turn define variables) fall under this category.

source

pub fn is_internally_pure(&self) -> bool

Is this statement pure within the containing block?

An internally pure statement only has side effects that disappear outside the block.

Currently only variable definitions (i.e. let and const) and import/export statements are internally pure, other than pure expressions.

source

pub const fn is_control_flow_break(&self) -> bool

Does this statement break the current control flow through the containing block?

Currently this is only true for return, throw, break and continue.

All statements following this statement will essentially be dead code.

source

pub fn walk<'a>( &'a self, path: &mut Vec<ASTNode<'a>>, on_node: &mut impl FnMut(&[ASTNode<'_>]) -> bool ) -> bool

Recursively walk this statement. Return false from the callback to terminate the walk.

Trait Implementations§

source§

impl Clone for Stmt

source§

fn clone(&self) -> Stmt

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Stmt

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Stmt

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Extend<Stmt> for StmtBlock

source§

fn extend<T: IntoIterator<Item = Stmt>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<'a> From<&'a Stmt> for ASTNode<'a>

source§

fn from(stmt: &'a Stmt) -> Self

Converts to this type from the input type.
source§

impl<T: IntoIterator<Item = Self>> From<(T, Position, Position)> for Stmt

source§

fn from(value: (T, Position, Position)) -> Self

Converts to this type from the input type.
source§

impl<T: IntoIterator<Item = Self>> From<(T, Span)> for Stmt

source§

fn from(value: (T, Span)) -> Self

Converts to this type from the input type.
source§

impl From<Stmt> for StmtBlock

source§

fn from(stmt: Stmt) -> Self

Converts to this type from the input type.
source§

impl From<StmtBlock> for Stmt

source§

fn from(block: StmtBlock) -> Self

Converts to this type from the input type.
source§

impl Hash for Stmt

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Stmt

§

impl !Send for Stmt

§

impl !Sync for Stmt

§

impl Unpin for Stmt

§

impl !UnwindSafe for Stmt

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.