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
Block(Vec<Stmt>)
Block: { stmts... }.
If
If statement: if (test) consequent else alternate.
Fields
While
While loop: while (test) body.
Fields
For
For loop: for (init; test; update) body.
Fields
ForIn
For-in/for-of loop: for (variable in/of iterable) body.
Fields
Return(Option<Expr>)
Return statement: return expr.
Break
Break statement.
Continue
Continue statement.
TryCatch
Try/catch/finally statement.
Fields
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
names: Vec<ImportName>Named/namespace/default specifiers. Empty means side-effect import.
Export
Export statement: export { X, Y } or re-export: export { X } from 'source'.
Fields
names: Vec<ExportName>Names being exported.
Class
Class definition: class Foo extends Bar { method() { ... } }.
Fields
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
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.
Implementations§
Source§impl Stmt
impl Stmt
pub fn expr(e: Expr) -> Self
pub fn let_decl(name: impl Into<String>, init: Option<Expr>) -> Self
pub fn const_decl(name: impl Into<String>, init: Expr) -> Self
pub fn block(stmts: Vec<Stmt>) -> Self
pub fn if_stmt(test: Expr, consequent: Stmt, alternate: Option<Stmt>) -> Self
pub fn while_loop(test: Expr, body: Stmt) -> Self
pub fn for_loop( init: Option<Stmt>, test: Option<Expr>, update: Option<Expr>, body: Stmt, ) -> Self
pub fn for_in(variable: impl Into<String>, iterable: Expr, body: Stmt) -> Self
pub fn return_stmt(expr: Option<Expr>) -> Self
pub fn break_stmt() -> Self
pub fn continue_stmt() -> Self
pub fn try_catch( body: Stmt, catch_param: Option<String>, catch_body: Option<Stmt>, finally_body: Option<Stmt>, ) -> Self
pub fn function(f: Function) -> Self
Sourcepub fn import(source: impl Into<String>, names: Vec<ImportName>) -> Self
pub fn import(source: impl Into<String>, names: Vec<ImportName>) -> Self
Create an import statement.
Sourcepub fn export(names: Vec<ExportName>, source: Option<String>) -> Self
pub fn export(names: Vec<ExportName>, source: Option<String>) -> Self
Create an export statement.
Sourcepub fn class(
name: impl Into<String>,
extends: Option<String>,
methods: Vec<Method>,
) -> Self
pub fn class( name: impl Into<String>, extends: Option<String>, methods: Vec<Method>, ) -> Self
Create a class definition.
Sourcepub fn destructure(pat: Pat, value: Expr, mutable: bool) -> Self
pub fn destructure(pat: Pat, value: Expr, mutable: bool) -> Self
Create a destructuring declaration.
Sourcepub fn comment_line(text: impl Into<String>) -> Self
pub fn comment_line(text: impl Into<String>) -> Self
Create a line comment from raw content (without // or -- delimiter).
Sourcepub fn comment_block(text: impl Into<String>) -> Self
pub fn comment_block(text: impl Into<String>) -> Self
Create a block comment from raw content (without /* */ or --[[ ]] delimiters).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Stmt
impl<'de> Deserialize<'de> for Stmt
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl StructureEq for Stmt
impl StructureEq for Stmt
Source§fn structure_eq(&self, other: &Self) -> bool
fn structure_eq(&self, other: &Self) -> bool
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request