Enum rustpython_ast::Ast
source · pub enum Ast<R = TextRange> {
Show 19 variants
Mod(Mod<R>),
Stmt(Stmt<R>),
Expr(Expr<R>),
ExprContext(ExprContext),
BoolOp(BoolOp),
Operator(Operator),
UnaryOp(UnaryOp),
CmpOp(CmpOp),
Comprehension(Comprehension<R>),
ExceptHandler(ExceptHandler<R>),
Arguments(Arguments<R>),
Arg(Arg<R>),
Keyword(Keyword<R>),
Alias(Alias<R>),
WithItem(WithItem<R>),
MatchCase(MatchCase<R>),
Pattern(Pattern<R>),
TypeIgnore(TypeIgnore<R>),
TypeParam(TypeParam<R>),
}
Variants§
Mod(Mod<R>)
Stmt(Stmt<R>)
Expr(Expr<R>)
ExprContext(ExprContext)
BoolOp(BoolOp)
Operator(Operator)
UnaryOp(UnaryOp)
CmpOp(CmpOp)
Comprehension(Comprehension<R>)
ExceptHandler(ExceptHandler<R>)
Arguments(Arguments<R>)
Arg(Arg<R>)
Keyword(Keyword<R>)
Alias(Alias<R>)
WithItem(WithItem<R>)
MatchCase(MatchCase<R>)
Pattern(Pattern<R>)
TypeIgnore(TypeIgnore<R>)
TypeParam(TypeParam<R>)
Implementations§
source§impl<R> Ast<R>
impl<R> Ast<R>
sourcepub fn as_module(&self) -> Option<&Mod<R>>
pub fn as_module(&self) -> Option<&Mod<R>>
Returns Some
if self
is a reference of variant Mod
, and None
otherwise.
sourcepub fn as_mut_module(&mut self) -> Option<&mut Mod<R>>
pub fn as_mut_module(&mut self) -> Option<&mut Mod<R>>
Returns Some
if self
is a mutable reference of variant Mod
, and None
otherwise.
sourcepub fn expect_module(self) -> Mod<R>where
Self: Debug,
pub fn expect_module(self) -> Mod<R>where
Self: Debug,
sourcepub fn module(self) -> Option<Mod<R>>
pub fn module(self) -> Option<Mod<R>>
Returns Some
if self
is of variant Mod
, and None
otherwise.
sourcepub fn as_stmt(&self) -> Option<&Stmt<R>>
pub fn as_stmt(&self) -> Option<&Stmt<R>>
Returns Some
if self
is a reference of variant Stmt
, and None
otherwise.
sourcepub fn as_mut_stmt(&mut self) -> Option<&mut Stmt<R>>
pub fn as_mut_stmt(&mut self) -> Option<&mut Stmt<R>>
Returns Some
if self
is a mutable reference of variant Stmt
, and None
otherwise.
sourcepub fn expect_stmt(self) -> Stmt<R>where
Self: Debug,
pub fn expect_stmt(self) -> Stmt<R>where
Self: Debug,
sourcepub fn stmt(self) -> Option<Stmt<R>>
pub fn stmt(self) -> Option<Stmt<R>>
Returns Some
if self
is of variant Stmt
, and None
otherwise.
sourcepub fn as_expr(&self) -> Option<&Expr<R>>
pub fn as_expr(&self) -> Option<&Expr<R>>
Returns Some
if self
is a reference of variant Expr
, and None
otherwise.
sourcepub fn as_mut_expr(&mut self) -> Option<&mut Expr<R>>
pub fn as_mut_expr(&mut self) -> Option<&mut Expr<R>>
Returns Some
if self
is a mutable reference of variant Expr
, and None
otherwise.
sourcepub fn expect_expr(self) -> Expr<R>where
Self: Debug,
pub fn expect_expr(self) -> Expr<R>where
Self: Debug,
sourcepub fn expr(self) -> Option<Expr<R>>
pub fn expr(self) -> Option<Expr<R>>
Returns Some
if self
is of variant Expr
, and None
otherwise.
sourcepub const fn is_expr_context(&self) -> bool
pub const fn is_expr_context(&self) -> bool
Returns true
if self
is of variant ExprContext
.
sourcepub fn as_expr_context(&self) -> Option<&ExprContext>
pub fn as_expr_context(&self) -> Option<&ExprContext>
Returns Some
if self
is a reference of variant ExprContext
, and None
otherwise.
sourcepub fn as_mut_expr_context(&mut self) -> Option<&mut ExprContext>
pub fn as_mut_expr_context(&mut self) -> Option<&mut ExprContext>
Returns Some
if self
is a mutable reference of variant ExprContext
, and None
otherwise.
sourcepub fn expect_expr_context(self) -> ExprContextwhere
Self: Debug,
pub fn expect_expr_context(self) -> ExprContextwhere
Self: Debug,
Unwraps the value, yielding the content of ExprContext
.
§Panics
Panics if the value is not ExprContext
, with a panic message including the content of self
.
sourcepub fn expr_context(self) -> Option<ExprContext>
pub fn expr_context(self) -> Option<ExprContext>
Returns Some
if self
is of variant ExprContext
, and None
otherwise.
sourcepub const fn is_bool_op(&self) -> bool
pub const fn is_bool_op(&self) -> bool
Returns true
if self
is of variant BoolOp
.
sourcepub fn as_bool_op(&self) -> Option<&BoolOp>
pub fn as_bool_op(&self) -> Option<&BoolOp>
Returns Some
if self
is a reference of variant BoolOp
, and None
otherwise.
sourcepub fn as_mut_bool_op(&mut self) -> Option<&mut BoolOp>
pub fn as_mut_bool_op(&mut self) -> Option<&mut BoolOp>
Returns Some
if self
is a mutable reference of variant BoolOp
, and None
otherwise.
sourcepub fn expect_bool_op(self) -> BoolOpwhere
Self: Debug,
pub fn expect_bool_op(self) -> BoolOpwhere
Self: Debug,
sourcepub fn bool_op(self) -> Option<BoolOp>
pub fn bool_op(self) -> Option<BoolOp>
Returns Some
if self
is of variant BoolOp
, and None
otherwise.
sourcepub const fn is_operator(&self) -> bool
pub const fn is_operator(&self) -> bool
Returns true
if self
is of variant Operator
.
sourcepub fn as_operator(&self) -> Option<&Operator>
pub fn as_operator(&self) -> Option<&Operator>
Returns Some
if self
is a reference of variant Operator
, and None
otherwise.
sourcepub fn as_mut_operator(&mut self) -> Option<&mut Operator>
pub fn as_mut_operator(&mut self) -> Option<&mut Operator>
Returns Some
if self
is a mutable reference of variant Operator
, and None
otherwise.
sourcepub fn expect_operator(self) -> Operatorwhere
Self: Debug,
pub fn expect_operator(self) -> Operatorwhere
Self: Debug,
sourcepub fn operator(self) -> Option<Operator>
pub fn operator(self) -> Option<Operator>
Returns Some
if self
is of variant Operator
, and None
otherwise.
sourcepub const fn is_unary_op(&self) -> bool
pub const fn is_unary_op(&self) -> bool
Returns true
if self
is of variant UnaryOp
.
sourcepub fn as_unary_op(&self) -> Option<&UnaryOp>
pub fn as_unary_op(&self) -> Option<&UnaryOp>
Returns Some
if self
is a reference of variant UnaryOp
, and None
otherwise.
sourcepub fn as_mut_unary_op(&mut self) -> Option<&mut UnaryOp>
pub fn as_mut_unary_op(&mut self) -> Option<&mut UnaryOp>
Returns Some
if self
is a mutable reference of variant UnaryOp
, and None
otherwise.
sourcepub fn expect_unary_op(self) -> UnaryOpwhere
Self: Debug,
pub fn expect_unary_op(self) -> UnaryOpwhere
Self: Debug,
sourcepub fn unary_op(self) -> Option<UnaryOp>
pub fn unary_op(self) -> Option<UnaryOp>
Returns Some
if self
is of variant UnaryOp
, and None
otherwise.
sourcepub fn as_cmp_op(&self) -> Option<&CmpOp>
pub fn as_cmp_op(&self) -> Option<&CmpOp>
Returns Some
if self
is a reference of variant CmpOp
, and None
otherwise.
sourcepub fn as_mut_cmp_op(&mut self) -> Option<&mut CmpOp>
pub fn as_mut_cmp_op(&mut self) -> Option<&mut CmpOp>
Returns Some
if self
is a mutable reference of variant CmpOp
, and None
otherwise.
sourcepub fn expect_cmp_op(self) -> CmpOpwhere
Self: Debug,
pub fn expect_cmp_op(self) -> CmpOpwhere
Self: Debug,
sourcepub fn cmp_op(self) -> Option<CmpOp>
pub fn cmp_op(self) -> Option<CmpOp>
Returns Some
if self
is of variant CmpOp
, and None
otherwise.
sourcepub const fn is_comprehension(&self) -> bool
pub const fn is_comprehension(&self) -> bool
Returns true
if self
is of variant Comprehension
.
sourcepub fn as_comprehension(&self) -> Option<&Comprehension<R>>
pub fn as_comprehension(&self) -> Option<&Comprehension<R>>
Returns Some
if self
is a reference of variant Comprehension
, and None
otherwise.
sourcepub fn as_mut_comprehension(&mut self) -> Option<&mut Comprehension<R>>
pub fn as_mut_comprehension(&mut self) -> Option<&mut Comprehension<R>>
Returns Some
if self
is a mutable reference of variant Comprehension
, and None
otherwise.
sourcepub fn expect_comprehension(self) -> Comprehension<R>where
Self: Debug,
pub fn expect_comprehension(self) -> Comprehension<R>where
Self: Debug,
Unwraps the value, yielding the content of Comprehension
.
§Panics
Panics if the value is not Comprehension
, with a panic message including the content of self
.
sourcepub fn comprehension(self) -> Option<Comprehension<R>>
pub fn comprehension(self) -> Option<Comprehension<R>>
Returns Some
if self
is of variant Comprehension
, and None
otherwise.
sourcepub const fn is_except_handler(&self) -> bool
pub const fn is_except_handler(&self) -> bool
Returns true
if self
is of variant ExceptHandler
.
sourcepub fn as_except_handler(&self) -> Option<&ExceptHandler<R>>
pub fn as_except_handler(&self) -> Option<&ExceptHandler<R>>
Returns Some
if self
is a reference of variant ExceptHandler
, and None
otherwise.
sourcepub fn as_mut_except_handler(&mut self) -> Option<&mut ExceptHandler<R>>
pub fn as_mut_except_handler(&mut self) -> Option<&mut ExceptHandler<R>>
Returns Some
if self
is a mutable reference of variant ExceptHandler
, and None
otherwise.
sourcepub fn expect_except_handler(self) -> ExceptHandler<R>where
Self: Debug,
pub fn expect_except_handler(self) -> ExceptHandler<R>where
Self: Debug,
Unwraps the value, yielding the content of ExceptHandler
.
§Panics
Panics if the value is not ExceptHandler
, with a panic message including the content of self
.
sourcepub fn except_handler(self) -> Option<ExceptHandler<R>>
pub fn except_handler(self) -> Option<ExceptHandler<R>>
Returns Some
if self
is of variant ExceptHandler
, and None
otherwise.
sourcepub const fn is_arguments(&self) -> bool
pub const fn is_arguments(&self) -> bool
Returns true
if self
is of variant Arguments
.
sourcepub fn as_arguments(&self) -> Option<&Arguments<R>>
pub fn as_arguments(&self) -> Option<&Arguments<R>>
Returns Some
if self
is a reference of variant Arguments
, and None
otherwise.
sourcepub fn as_mut_arguments(&mut self) -> Option<&mut Arguments<R>>
pub fn as_mut_arguments(&mut self) -> Option<&mut Arguments<R>>
Returns Some
if self
is a mutable reference of variant Arguments
, and None
otherwise.
sourcepub fn expect_arguments(self) -> Arguments<R>where
Self: Debug,
pub fn expect_arguments(self) -> Arguments<R>where
Self: Debug,
sourcepub fn arguments(self) -> Option<Arguments<R>>
pub fn arguments(self) -> Option<Arguments<R>>
Returns Some
if self
is of variant Arguments
, and None
otherwise.
sourcepub fn as_arg(&self) -> Option<&Arg<R>>
pub fn as_arg(&self) -> Option<&Arg<R>>
Returns Some
if self
is a reference of variant Arg
, and None
otherwise.
sourcepub fn as_mut_arg(&mut self) -> Option<&mut Arg<R>>
pub fn as_mut_arg(&mut self) -> Option<&mut Arg<R>>
Returns Some
if self
is a mutable reference of variant Arg
, and None
otherwise.
sourcepub fn expect_arg(self) -> Arg<R>where
Self: Debug,
pub fn expect_arg(self) -> Arg<R>where
Self: Debug,
sourcepub const fn is_keyword(&self) -> bool
pub const fn is_keyword(&self) -> bool
Returns true
if self
is of variant Keyword
.
sourcepub fn as_keyword(&self) -> Option<&Keyword<R>>
pub fn as_keyword(&self) -> Option<&Keyword<R>>
Returns Some
if self
is a reference of variant Keyword
, and None
otherwise.
sourcepub fn as_mut_keyword(&mut self) -> Option<&mut Keyword<R>>
pub fn as_mut_keyword(&mut self) -> Option<&mut Keyword<R>>
Returns Some
if self
is a mutable reference of variant Keyword
, and None
otherwise.
sourcepub fn expect_keyword(self) -> Keyword<R>where
Self: Debug,
pub fn expect_keyword(self) -> Keyword<R>where
Self: Debug,
sourcepub fn keyword(self) -> Option<Keyword<R>>
pub fn keyword(self) -> Option<Keyword<R>>
Returns Some
if self
is of variant Keyword
, and None
otherwise.
sourcepub fn as_alias(&self) -> Option<&Alias<R>>
pub fn as_alias(&self) -> Option<&Alias<R>>
Returns Some
if self
is a reference of variant Alias
, and None
otherwise.
sourcepub fn as_mut_alias(&mut self) -> Option<&mut Alias<R>>
pub fn as_mut_alias(&mut self) -> Option<&mut Alias<R>>
Returns Some
if self
is a mutable reference of variant Alias
, and None
otherwise.
sourcepub fn expect_alias(self) -> Alias<R>where
Self: Debug,
pub fn expect_alias(self) -> Alias<R>where
Self: Debug,
sourcepub fn alias(self) -> Option<Alias<R>>
pub fn alias(self) -> Option<Alias<R>>
Returns Some
if self
is of variant Alias
, and None
otherwise.
sourcepub const fn is_with_item(&self) -> bool
pub const fn is_with_item(&self) -> bool
Returns true
if self
is of variant WithItem
.
sourcepub fn as_with_item(&self) -> Option<&WithItem<R>>
pub fn as_with_item(&self) -> Option<&WithItem<R>>
Returns Some
if self
is a reference of variant WithItem
, and None
otherwise.
sourcepub fn as_mut_with_item(&mut self) -> Option<&mut WithItem<R>>
pub fn as_mut_with_item(&mut self) -> Option<&mut WithItem<R>>
Returns Some
if self
is a mutable reference of variant WithItem
, and None
otherwise.
sourcepub fn expect_with_item(self) -> WithItem<R>where
Self: Debug,
pub fn expect_with_item(self) -> WithItem<R>where
Self: Debug,
sourcepub fn with_item(self) -> Option<WithItem<R>>
pub fn with_item(self) -> Option<WithItem<R>>
Returns Some
if self
is of variant WithItem
, and None
otherwise.
sourcepub const fn is_match_case(&self) -> bool
pub const fn is_match_case(&self) -> bool
Returns true
if self
is of variant MatchCase
.
sourcepub fn as_match_case(&self) -> Option<&MatchCase<R>>
pub fn as_match_case(&self) -> Option<&MatchCase<R>>
Returns Some
if self
is a reference of variant MatchCase
, and None
otherwise.
sourcepub fn as_mut_match_case(&mut self) -> Option<&mut MatchCase<R>>
pub fn as_mut_match_case(&mut self) -> Option<&mut MatchCase<R>>
Returns Some
if self
is a mutable reference of variant MatchCase
, and None
otherwise.
sourcepub fn expect_match_case(self) -> MatchCase<R>where
Self: Debug,
pub fn expect_match_case(self) -> MatchCase<R>where
Self: Debug,
sourcepub fn match_case(self) -> Option<MatchCase<R>>
pub fn match_case(self) -> Option<MatchCase<R>>
Returns Some
if self
is of variant MatchCase
, and None
otherwise.
sourcepub const fn is_pattern(&self) -> bool
pub const fn is_pattern(&self) -> bool
Returns true
if self
is of variant Pattern
.
sourcepub fn as_pattern(&self) -> Option<&Pattern<R>>
pub fn as_pattern(&self) -> Option<&Pattern<R>>
Returns Some
if self
is a reference of variant Pattern
, and None
otherwise.
sourcepub fn as_mut_pattern(&mut self) -> Option<&mut Pattern<R>>
pub fn as_mut_pattern(&mut self) -> Option<&mut Pattern<R>>
Returns Some
if self
is a mutable reference of variant Pattern
, and None
otherwise.
sourcepub fn expect_pattern(self) -> Pattern<R>where
Self: Debug,
pub fn expect_pattern(self) -> Pattern<R>where
Self: Debug,
sourcepub fn pattern(self) -> Option<Pattern<R>>
pub fn pattern(self) -> Option<Pattern<R>>
Returns Some
if self
is of variant Pattern
, and None
otherwise.
sourcepub const fn is_type_ignore(&self) -> bool
pub const fn is_type_ignore(&self) -> bool
Returns true
if self
is of variant TypeIgnore
.
sourcepub fn as_type_ignore(&self) -> Option<&TypeIgnore<R>>
pub fn as_type_ignore(&self) -> Option<&TypeIgnore<R>>
Returns Some
if self
is a reference of variant TypeIgnore
, and None
otherwise.
sourcepub fn as_mut_type_ignore(&mut self) -> Option<&mut TypeIgnore<R>>
pub fn as_mut_type_ignore(&mut self) -> Option<&mut TypeIgnore<R>>
Returns Some
if self
is a mutable reference of variant TypeIgnore
, and None
otherwise.
sourcepub fn expect_type_ignore(self) -> TypeIgnore<R>where
Self: Debug,
pub fn expect_type_ignore(self) -> TypeIgnore<R>where
Self: Debug,
Unwraps the value, yielding the content of TypeIgnore
.
§Panics
Panics if the value is not TypeIgnore
, with a panic message including the content of self
.
sourcepub fn type_ignore(self) -> Option<TypeIgnore<R>>
pub fn type_ignore(self) -> Option<TypeIgnore<R>>
Returns Some
if self
is of variant TypeIgnore
, and None
otherwise.
sourcepub const fn is_type_param(&self) -> bool
pub const fn is_type_param(&self) -> bool
Returns true
if self
is of variant TypeParam
.
sourcepub fn as_type_param(&self) -> Option<&TypeParam<R>>
pub fn as_type_param(&self) -> Option<&TypeParam<R>>
Returns Some
if self
is a reference of variant TypeParam
, and None
otherwise.
sourcepub fn as_mut_type_param(&mut self) -> Option<&mut TypeParam<R>>
pub fn as_mut_type_param(&mut self) -> Option<&mut TypeParam<R>>
Returns Some
if self
is a mutable reference of variant TypeParam
, and None
otherwise.
sourcepub fn expect_type_param(self) -> TypeParam<R>where
Self: Debug,
pub fn expect_type_param(self) -> TypeParam<R>where
Self: Debug,
sourcepub fn type_param(self) -> Option<TypeParam<R>>
pub fn type_param(self) -> Option<TypeParam<R>>
Returns Some
if self
is of variant TypeParam
, and None
otherwise.