Skip to main content

PythonExpr

Enum PythonExpr 

Source
pub enum PythonExpr {
Show 26 variants Lit(PythonLit), Var(String), BinOp(String, Box<PythonExpr>, Box<PythonExpr>), UnaryOp(String, Box<PythonExpr>), Call(Box<PythonExpr>, Vec<PythonExpr>, Vec<(String, PythonExpr)>), Attr(Box<PythonExpr>, String), Subscript(Box<PythonExpr>, Box<PythonExpr>), Lambda(Vec<String>, Box<PythonExpr>), IfExpr(Box<PythonExpr>, Box<PythonExpr>, Box<PythonExpr>), ListComp(Box<PythonExpr>, String, Box<PythonExpr>, Option<Box<PythonExpr>>), DictComp(Box<PythonExpr>, Box<PythonExpr>, String, String, Box<PythonExpr>), SetComp(Box<PythonExpr>, String, Box<PythonExpr>, Option<Box<PythonExpr>>), GenExpr(Box<PythonExpr>, String, Box<PythonExpr>, Option<Box<PythonExpr>>), Tuple(Vec<PythonExpr>), List(Vec<PythonExpr>), Dict(Vec<(PythonExpr, PythonExpr)>), Set(Vec<PythonExpr>), Await(Box<PythonExpr>), Yield(Option<Box<PythonExpr>>), YieldFrom(Box<PythonExpr>), Match(Box<PythonExpr>), FString(Vec<FStringPart>), Walrus(String, Box<PythonExpr>), Star(Box<PythonExpr>), DoubleStar(Box<PythonExpr>), Slice(Option<Box<PythonExpr>>, Option<Box<PythonExpr>>, Option<Box<PythonExpr>>),
}
Expand description

Python expression for code generation.

Variants§

§

Lit(PythonLit)

A literal value: 42, "hello", True, None, etc.

§

Var(String)

A variable identifier: x, my_var

§

BinOp(String, Box<PythonExpr>, Box<PythonExpr>)

Binary operator: lhs + rhs, a == b, etc.

§

UnaryOp(String, Box<PythonExpr>)

Unary operator: -x, not x, ~x

§

Call(Box<PythonExpr>, Vec<PythonExpr>, Vec<(String, PythonExpr)>)

Function call: f(a, b, key=val)

§

Attr(Box<PythonExpr>, String)

Attribute access: obj.field

§

Subscript(Box<PythonExpr>, Box<PythonExpr>)

Subscript: obj[idx]

§

Lambda(Vec<String>, Box<PythonExpr>)

Lambda expression: lambda x, y: x + y

§

IfExpr(Box<PythonExpr>, Box<PythonExpr>, Box<PythonExpr>)

Conditional (ternary) expression: a if cond else b

§

ListComp(Box<PythonExpr>, String, Box<PythonExpr>, Option<Box<PythonExpr>>)

List comprehension: [expr for var in iter if cond]

§

DictComp(Box<PythonExpr>, Box<PythonExpr>, String, String, Box<PythonExpr>)

Dict comprehension: {k: v for k, v in items}

§

SetComp(Box<PythonExpr>, String, Box<PythonExpr>, Option<Box<PythonExpr>>)

Set comprehension: {x for x in iter}

§

GenExpr(Box<PythonExpr>, String, Box<PythonExpr>, Option<Box<PythonExpr>>)

Generator expression: (expr for var in iter if cond)

§

Tuple(Vec<PythonExpr>)

Tuple literal: (a, b, c) or a, b, c

§

List(Vec<PythonExpr>)

List literal: [a, b, c]

§

Dict(Vec<(PythonExpr, PythonExpr)>)

Dict literal: {"key": val, ...}

§

Set(Vec<PythonExpr>)

Set literal: {a, b, c}

§

Await(Box<PythonExpr>)

Await expression: await expr

§

Yield(Option<Box<PythonExpr>>)

Yield expression: yield expr

§

YieldFrom(Box<PythonExpr>)

Yield from expression: yield from expr

§

Match(Box<PythonExpr>)

Match expression (Python 3.10+): used as target in match stmt

§

FString(Vec<FStringPart>)

f-string: f"hello {name}!"

§

Walrus(String, Box<PythonExpr>)

Walrus operator (assignment expression): name := expr

§

Star(Box<PythonExpr>)

Star expression: *args

§

DoubleStar(Box<PythonExpr>)

Double-star expression: **kwargs

§

Slice(Option<Box<PythonExpr>>, Option<Box<PythonExpr>>, Option<Box<PythonExpr>>)

Slice: a:b:c

Trait Implementations§

Source§

impl Clone for PythonExpr

Source§

fn clone(&self) -> PythonExpr

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 PythonExpr

Source§

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

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

impl Display for PythonExpr

Source§

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

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

impl PartialEq for PythonExpr

Source§

fn eq(&self, other: &PythonExpr) -> 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 StructuralPartialEq for PythonExpr

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.