Skip to main content

Expression

Enum Expression 

Source
pub enum Expression {
Show 26 variants Literal(Literal), Name(String), BinaryOp { left: Box<Expression>, operator: BinaryOperator, right: Box<Expression>, }, UnaryOp { operator: UnaryOperator, operand: Box<Expression>, }, BoolOp { operator: BoolOperator, values: Vec<Expression>, }, Compare { left: Box<Expression>, ops: Vec<CompareOperator>, comparators: Vec<Expression>, }, Call { func: Box<Expression>, args: Vec<Expression>, keywords: Vec<Keyword>, }, Attribute { value: Box<Expression>, attr: String, }, Subscript { value: Box<Expression>, slice: Box<Expression>, }, List { elts: Vec<Expression>, }, Tuple { elts: Vec<Expression>, }, Slice { lower: Option<Box<Expression>>, upper: Option<Box<Expression>>, step: Option<Box<Expression>>, }, Dict { keys: Vec<Option<Expression>>, values: Vec<Expression>, }, Set { elts: Vec<Expression>, }, ListComp { elt: Box<Expression>, generators: Vec<Comprehension>, }, DictComp { key: Box<Expression>, value: Box<Expression>, generators: Vec<Comprehension>, }, SetComp { elt: Box<Expression>, generators: Vec<Comprehension>, }, GeneratorExp { elt: Box<Expression>, generators: Vec<Comprehension>, }, Lambda { args: Vec<Parameter>, body: Box<Expression>, }, IfExp { test: Box<Expression>, body: Box<Expression>, orelse: Box<Expression>, }, JoinedStr { values: Vec<Expression>, }, FormattedValue { value: Box<Expression>, conversion: usize, format_spec: Option<Box<Expression>>, }, Yield(Option<Box<Expression>>), YieldFrom(Box<Expression>), Await(Box<Expression>), Starred { value: Box<Expression>, is_double: bool, },
}
Expand description

Represents a Python expression.

Variants§

§

Literal(Literal)

Literal value

§

Name(String)

Identifier name

§

BinaryOp

Binary operation

Fields

§left: Box<Expression>

Left operand

§operator: BinaryOperator

Binary operator

§right: Box<Expression>

Right operand

§

UnaryOp

Unary operation

Fields

§operator: UnaryOperator

Unary operator

§operand: Box<Expression>

Operand

§

BoolOp

Boolean operation (and, or)

Fields

§operator: BoolOperator

Boolean operator

§values: Vec<Expression>

List of values

§

Compare

Comparison operation

Fields

§left: Box<Expression>

Leftmost operand

§ops: Vec<CompareOperator>

Comparison operators

§comparators: Vec<Expression>

Subsequent operands

§

Call

Function call

Fields

§func: Box<Expression>

Function being called

§args: Vec<Expression>

Positional arguments

§keywords: Vec<Keyword>

Keyword arguments

§

Attribute

Attribute access

Fields

§value: Box<Expression>

Base expression

§attr: String

Attribute name

§

Subscript

Subscript access

Fields

§value: Box<Expression>

Base expression

§slice: Box<Expression>

Slice or index expression

§

List

List literal

Fields

§elts: Vec<Expression>

List elements

§

Tuple

Tuple literal

Fields

§elts: Vec<Expression>

Tuple elements

§

Slice

Slice expression

Fields

§lower: Option<Box<Expression>>

Optional lower bound

§upper: Option<Box<Expression>>

Optional upper bound

§step: Option<Box<Expression>>

Optional step

§

Dict

Dictionary literal

Fields

§keys: Vec<Option<Expression>>

Optional keys

§values: Vec<Expression>

Values

§

Set

Set literal

Fields

§elts: Vec<Expression>

Set elements

§

ListComp

List comprehension

Fields

§elt: Box<Expression>

Result expression

§generators: Vec<Comprehension>

Generators

§

DictComp

Dictionary comprehension

Fields

§key: Box<Expression>

Key expression

§value: Box<Expression>

Value expression

§generators: Vec<Comprehension>

Generators

§

SetComp

Set comprehension

Fields

§elt: Box<Expression>

Result expression

§generators: Vec<Comprehension>

Generators

§

GeneratorExp

Generator expression

Fields

§elt: Box<Expression>

Result expression

§generators: Vec<Comprehension>

Generators

§

Lambda

Lambda expression

Fields

§args: Vec<Parameter>

Lambda arguments

§body: Box<Expression>

Lambda body

§

IfExp

Conditional expression (ternary operator)

Fields

§test: Box<Expression>

Test expression

§body: Box<Expression>

Body expression

§orelse: Box<Expression>

Else expression

§

JoinedStr

f-string

Fields

§values: Vec<Expression>

f-string parts

§

FormattedValue

Formatted value within an f-string

Fields

§value: Box<Expression>

Value to format

§conversion: usize

Conversion type

§format_spec: Option<Box<Expression>>

Optional format specification

§

Yield(Option<Box<Expression>>)

Yield expression

§

YieldFrom(Box<Expression>)

Yield from expression

§

Await(Box<Expression>)

Await expression

§

Starred

Starred expression (*args, **kwargs)

Fields

§value: Box<Expression>

Value being starred

§is_double: bool

Whether it’s a double star (**kwargs)

Implementations§

Source§

impl Expression

Source

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

Creates a name expression.

Source

pub fn string(value: impl Into<String>) -> Self

Creates a string literal expression.

Source

pub fn integer(value: i64) -> Self

Creates an integer literal expression.

Source

pub fn float(value: f64) -> Self

Creates a float literal expression.

Source

pub fn boolean(value: bool) -> Self

Creates a boolean literal expression.

Source

pub fn none() -> Self

Creates a None literal expression.

Trait Implementations§

Source§

impl Clone for Expression

Source§

fn clone(&self) -> Expression

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 Expression

Source§

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

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

impl<'de> Deserialize<'de> for Expression

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 Expression

Source§

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

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 Expression

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>,