Skip to main content

Stmt

Enum Stmt 

Source
pub enum Stmt {
Show 17 variants Expr(Expr), Let { name: String, init: Option<Expr>, mutable: bool, type_annotation: Option<String>, span: Option<Span>, }, Block(Vec<Stmt>), If { test: Expr, consequent: Box<Stmt>, alternate: Option<Box<Stmt>>, span: Option<Span>, }, While { test: Expr, body: Box<Stmt>, span: Option<Span>, }, For { init: Option<Box<Stmt>>, test: Option<Expr>, update: Option<Expr>, body: Box<Stmt>, span: Option<Span>, }, ForIn { variable: String, iterable: Expr, body: Box<Stmt>, span: Option<Span>, }, Return(Option<Expr>), Break, Continue, TryCatch { body: Box<Stmt>, catch_param: Option<String>, catch_body: Option<Box<Stmt>>, finally_body: Option<Box<Stmt>>, span: Option<Span>, }, Function(Function), Import { source: String, names: Vec<ImportName>, span: Option<Span>, }, Export { names: Vec<ExportName>, source: Option<String>, span: Option<Span>, }, Class { name: String, extends: Option<String>, methods: Vec<Method>, span: Option<Span>, }, Destructure { pat: Pat, value: Expr, mutable: bool, span: Option<Span>, }, Comment { text: String, block: bool, span: Option<Span>, },
}
Expand description

A statement (doesn’t produce a value directly).

Variants§

§

Expr(Expr)

Expression statement: expr;.

§

Let

Variable declaration: let name = init or const name = init.

Fields

§name: String
§init: Option<Expr>
§mutable: bool
§type_annotation: Option<String>

Optional type annotation (e.g. string for let x: string = ...).

§span: Option<Span>

Source location (populated by readers; ignored by writers).

§

Block(Vec<Stmt>)

Block: { stmts... }.

§

If

If statement: if (test) consequent else alternate.

Fields

§test: Expr
§consequent: Box<Stmt>
§alternate: Option<Box<Stmt>>
§span: Option<Span>

Source location (populated by readers; ignored by writers).

§

While

While loop: while (test) body.

Fields

§test: Expr
§body: Box<Stmt>
§span: Option<Span>

Source location (populated by readers; ignored by writers).

§

For

For loop: for (init; test; update) body.

Fields

§init: Option<Box<Stmt>>
§test: Option<Expr>
§update: Option<Expr>
§body: Box<Stmt>
§span: Option<Span>

Source location (populated by readers; ignored by writers).

§

ForIn

For-in/for-of loop: for (variable in/of iterable) body.

Fields

§variable: String
§iterable: Expr
§body: Box<Stmt>
§span: Option<Span>

Source location (populated by readers; ignored by writers).

§

Return(Option<Expr>)

Return statement: return expr.

§

Break

Break statement.

§

Continue

Continue statement.

§

TryCatch

Try/catch/finally statement.

Fields

§body: Box<Stmt>
§catch_param: Option<String>
§catch_body: Option<Box<Stmt>>
§finally_body: Option<Box<Stmt>>
§span: Option<Span>

Source location (populated by readers; ignored by writers).

§

Function(Function)

Function declaration.

§

Import

Import statement: import { X, Y } from 'source' or import * as ns from 'source'.

names is empty for side-effect-only imports: import './side-effect'.

Fields

§source: String

The module specifier string (e.g. "./module", "react").

§names: Vec<ImportName>

Named/namespace/default specifiers. Empty means side-effect import.

§span: Option<Span>

Source location (populated by readers; ignored by writers).

§

Export

Export statement: export { X, Y } or re-export: export { X } from 'source'.

Fields

§names: Vec<ExportName>

Names being exported.

§source: Option<String>

Source module for re-exports (e.g. "./other" in export { X } from './other').

§span: Option<Span>

Source location (populated by readers; ignored by writers).

§

Class

Class definition: class Foo extends Bar { method() { ... } }.

Fields

§name: String

Class name.

§extends: Option<String>

Superclass name (e.g. "Bar" in class Foo extends Bar).

§methods: Vec<Method>

Methods (including constructor).

§span: Option<Span>

Source location (populated by readers; ignored by writers).

§

Destructure

Destructuring declaration: const { a, b: c } = obj or const [x, y] = arr.

The pattern captures the full structural binding; the mutable flag distinguishes let from const. Writers emit the appropriate destructuring syntax for the target language (TypeScript/JavaScript: const { a } = obj; Python: a, b = obj).

Fields

§pat: Pat

The binding pattern.

§value: Expr

The right-hand side expression.

§mutable: bool

true for let (mutable), false for const.

§span: Option<Span>

Source location (populated by readers; ignored by writers).

§

Comment

Comment (line or block). Used to preserve documentation comments during translation.

text is the raw comment text including delimiters (e.g. // foo, /* bar */, /** JSDoc */, -- Lua, --[[ block ]]). Writers emit the text verbatim so the correct delimiter style for the target language must be supplied by the writer.

For cross-language translation, use Stmt::comment_line(text) / Stmt::comment_block(text) which store only the content; writers format it according to the target language.

Fields

§text: String

Comment content (without delimiters).

§block: bool

Whether this was originally a block comment (/* */, --[[ ]]).

§span: Option<Span>

Source location.

Implementations§

Source§

impl Stmt

Source

pub fn expr(e: Expr) -> Self

Source

pub fn let_decl(name: impl Into<String>, init: Option<Expr>) -> Self

Source

pub fn const_decl(name: impl Into<String>, init: Expr) -> Self

Source

pub fn block(stmts: Vec<Stmt>) -> Self

Source

pub fn if_stmt(test: Expr, consequent: Stmt, alternate: Option<Stmt>) -> Self

Source

pub fn while_loop(test: Expr, body: Stmt) -> Self

Source

pub fn for_loop( init: Option<Stmt>, test: Option<Expr>, update: Option<Expr>, body: Stmt, ) -> Self

Source

pub fn for_in(variable: impl Into<String>, iterable: Expr, body: Stmt) -> Self

Source

pub fn return_stmt(expr: Option<Expr>) -> Self

Source

pub fn break_stmt() -> Self

Source

pub fn continue_stmt() -> Self

Source

pub fn try_catch( body: Stmt, catch_param: Option<String>, catch_body: Option<Stmt>, finally_body: Option<Stmt>, ) -> Self

Source

pub fn function(f: Function) -> Self

Source

pub fn import(source: impl Into<String>, names: Vec<ImportName>) -> Self

Create an import statement.

Source

pub fn export(names: Vec<ExportName>, source: Option<String>) -> Self

Create an export statement.

Source

pub fn class( name: impl Into<String>, extends: Option<String>, methods: Vec<Method>, ) -> Self

Create a class definition.

Source

pub fn destructure(pat: Pat, value: Expr, mutable: bool) -> Self

Create a destructuring declaration.

Source

pub fn comment_line(text: impl Into<String>) -> Self

Create a line comment from raw content (without // or -- delimiter).

Source

pub fn comment_block(text: impl Into<String>) -> Self

Create a block comment from raw content (without /* */ or --[[ ]] delimiters).

Source

pub fn with_span(self, span: Span) -> Self

Attach a source location span to this statement.

Trait Implementations§

Source§

impl Clone for Stmt

Source§

fn clone(&self) -> Stmt

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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<'de> Deserialize<'de> for Stmt

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Stmt

Source§

fn eq(&self, other: &Stmt) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Stmt

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructureEq for Stmt

Source§

fn structure_eq(&self, other: &Self) -> bool

Compare two values for structural equality.
Source§

impl StructuralPartialEq for Stmt

Auto Trait Implementations§

§

impl Freeze for Stmt

§

impl RefUnwindSafe for Stmt

§

impl Send for Stmt

§

impl Sync for Stmt

§

impl Unpin for Stmt

§

impl UnsafeUnpin for Stmt

§

impl UnwindSafe for Stmt

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

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

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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,