Skip to main content

Statement

Enum Statement 

Source
pub enum Statement {
Show 25 variants FunctionDef { decorators: Vec<Expression>, name: String, parameters: Vec<Parameter>, return_type: Option<Type>, body: Vec<Statement>, }, AsyncFunctionDef { decorators: Vec<Expression>, name: String, parameters: Vec<Parameter>, return_type: Option<Type>, body: Vec<Statement>, }, ClassDef { decorators: Vec<Expression>, name: String, bases: Vec<Expression>, body: Vec<Statement>, }, Assignment { target: Expression, value: Expression, }, AugmentedAssignment { target: Expression, operator: AugmentedOperator, value: Expression, }, Expression(Expression), Return(Option<Expression>), If { test: Expression, body: Vec<Statement>, orelse: Vec<Statement>, }, For { target: Expression, iter: Expression, body: Vec<Statement>, orelse: Vec<Statement>, }, AsyncFor { target: Expression, iter: Expression, body: Vec<Statement>, orelse: Vec<Statement>, }, While { test: Expression, body: Vec<Statement>, orelse: Vec<Statement>, }, Break, Continue, Pass, Import { names: Vec<ImportName>, }, ImportFrom { module: Option<String>, names: Vec<ImportName>, }, Global { names: Vec<String>, }, Nonlocal { names: Vec<String>, }, Try { body: Vec<Statement>, handlers: Vec<ExceptHandler>, orelse: Vec<Statement>, finalbody: Vec<Statement>, }, Raise { exc: Option<Expression>, cause: Option<Expression>, }, With { items: Vec<WithItem>, body: Vec<Statement>, }, AsyncWith { items: Vec<WithItem>, body: Vec<Statement>, }, Assert { test: Expression, msg: Option<Expression>, }, Match { subject: Expression, cases: Vec<MatchCase>, }, Delete { targets: Vec<Expression>, },
}
Expand description

Represents a Python statement.

Variants§

§

FunctionDef

Function definition

Fields

§decorators: Vec<Expression>

Decorators applied to the function

§name: String

Function name

§parameters: Vec<Parameter>

List of parameters

§return_type: Option<Type>

Optional return type annotation

§body: Vec<Statement>

Function body

§

AsyncFunctionDef

Async function definition

Fields

§decorators: Vec<Expression>

Decorators applied to the function

§name: String

Function name

§parameters: Vec<Parameter>

List of parameters

§return_type: Option<Type>

Optional return type annotation

§body: Vec<Statement>

Function body

§

ClassDef

Class definition

Fields

§decorators: Vec<Expression>

Decorators applied to the class

§name: String

Class name

§bases: Vec<Expression>

Base classes

§body: Vec<Statement>

Class body

§

Assignment

Variable assignment

Fields

§target: Expression

Target expression

§value: Expression

Value expression

§

AugmentedAssignment

Augmented assignment (e.g., +=, -=)

Fields

§target: Expression

Target expression

§operator: AugmentedOperator

Augmented operator

§value: Expression

Value expression

§

Expression(Expression)

Expression statement

§

Return(Option<Expression>)

Return statement

§

If

If statement

Fields

§test: Expression

Test expression

§body: Vec<Statement>

Body of the if block

§orelse: Vec<Statement>

Else block (or empty)

§

For

For loop

Fields

§target: Expression

Loop target

§iter: Expression

Iterable expression

§body: Vec<Statement>

Loop body

§orelse: Vec<Statement>

Else block (or empty)

§

AsyncFor

Async for loop

Fields

§target: Expression

Loop target

§iter: Expression

Iterable expression

§body: Vec<Statement>

Loop body

§orelse: Vec<Statement>

Else block (or empty)

§

While

While loop

Fields

§test: Expression

Test expression

§body: Vec<Statement>

Loop body

§orelse: Vec<Statement>

Else block (or empty)

§

Break

Break statement

§

Continue

Continue statement

§

Pass

Pass statement

§

Import

Import statement

Fields

§names: Vec<ImportName>

List of names being imported

§

ImportFrom

From-import statement

Fields

§module: Option<String>

Optional module name

§names: Vec<ImportName>

List of names being imported

§

Global

Global statement

Fields

§names: Vec<String>

List of global names

§

Nonlocal

Nonlocal statement

Fields

§names: Vec<String>

List of nonlocal names

§

Try

Try statement

Fields

§body: Vec<Statement>

Try body

§handlers: Vec<ExceptHandler>

Exception handlers

§orelse: Vec<Statement>

Else block

§finalbody: Vec<Statement>

Finally block

§

Raise

Raise statement

Fields

§exc: Option<Expression>

Optional exception

§cause: Option<Expression>

Optional cause

§

With

With statement

Fields

§items: Vec<WithItem>

With items

§body: Vec<Statement>

With body

§

AsyncWith

Async with statement

Fields

§items: Vec<WithItem>

With items

§body: Vec<Statement>

With body

§

Assert

Assert statement

Fields

§test: Expression

Test expression

§msg: Option<Expression>

Optional error message

§

Match

Match statement

Fields

§subject: Expression

Subject expression

§cases: Vec<MatchCase>

Match cases

§

Delete

Delete statement

Fields

§targets: Vec<Expression>

Targets to delete

Implementations§

Source§

impl Statement

Source

pub fn function_def( name: impl Into<String>, parameters: Vec<Parameter>, return_type: Option<Type>, body: Vec<Statement>, ) -> Self

Creates a function definition statement.

Source

pub fn assignment(target: Expression, value: Expression) -> Self

Creates an assignment statement.

Source

pub fn expression(expr: Expression) -> Self

Creates an expression statement.

Source

pub fn return_stmt(value: Option<Expression>) -> Self

Creates a return statement.

Trait Implementations§

Source§

impl Clone for Statement

Source§

fn clone(&self) -> Statement

Returns a duplicate 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 Statement

Source§

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

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

impl<'de> Deserialize<'de> for Statement

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 Statement

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 Statement

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 StructuralPartialEq for Statement

Auto Trait Implementations§

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, 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> 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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,