// This file is automatically generated based on the file `./generated.rs.tera` when `cargo gen-syntax` is run // Do not edit manually //! This module contains auto-generated Rust AST. Like `SyntaxNode`s, AST nodes //! are generic over ownership: `X<'a>` things are `Copy` references, `XNode` //! are Arc-based. You can switch between the two variants using `.owned` and //! `.borrowed` functions. Most of the code works with borowed mode, and only //! this mode has all AST accessors. #![cfg_attr(rustfmt, rustfmt_skip)] use rowan::TransparentNewType; use crate::{ SyntaxNode, SyntaxKind::*, yellow::{RaTypes, TreeArc}, ast::{self, AstNode}, }; // ArgList #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct ArgList { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for ArgList { type Repr = rowan::SyntaxNode; } impl AstNode for ArgList { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { ARG_LIST => Some(ArgList::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl ArgList { pub fn args(&self) -> impl Iterator { super::children(self) } } // ArrayExpr #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct ArrayExpr { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for ArrayExpr { type Repr = rowan::SyntaxNode; } impl AstNode for ArrayExpr { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { ARRAY_EXPR => Some(ArrayExpr::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl ArrayExpr { pub fn exprs(&self) -> impl Iterator { super::children(self) } } // ArrayType #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct ArrayType { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for ArrayType { type Repr = rowan::SyntaxNode; } impl AstNode for ArrayType { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { ARRAY_TYPE => Some(ArrayType::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl ArrayType { pub fn type_ref(&self) -> Option<&TypeRef> { super::child_opt(self) } pub fn expr(&self) -> Option<&Expr> { super::child_opt(self) } } // AssocTypeArg #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct AssocTypeArg { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for AssocTypeArg { type Repr = rowan::SyntaxNode; } impl AstNode for AssocTypeArg { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { ASSOC_TYPE_ARG => Some(AssocTypeArg::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl AssocTypeArg { pub fn name_ref(&self) -> Option<&NameRef> { super::child_opt(self) } pub fn type_ref(&self) -> Option<&TypeRef> { super::child_opt(self) } } // Attr #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct Attr { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for Attr { type Repr = rowan::SyntaxNode; } impl AstNode for Attr { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { ATTR => Some(Attr::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl Attr { pub fn value(&self) -> Option<&TokenTree> { super::child_opt(self) } } // BinExpr #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct BinExpr { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for BinExpr { type Repr = rowan::SyntaxNode; } impl AstNode for BinExpr { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { BIN_EXPR => Some(BinExpr::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl BinExpr {} // BindPat #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct BindPat { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for BindPat { type Repr = rowan::SyntaxNode; } impl AstNode for BindPat { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { BIND_PAT => Some(BindPat::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl ast::NameOwner for BindPat {} impl BindPat { pub fn pat(&self) -> Option<&Pat> { super::child_opt(self) } } // Block #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct Block { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for Block { type Repr = rowan::SyntaxNode; } impl AstNode for Block { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { BLOCK => Some(Block::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl Block { pub fn statements(&self) -> impl Iterator { super::children(self) } pub fn expr(&self) -> Option<&Expr> { super::child_opt(self) } } // BlockExpr #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct BlockExpr { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for BlockExpr { type Repr = rowan::SyntaxNode; } impl AstNode for BlockExpr { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { BLOCK_EXPR => Some(BlockExpr::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl BlockExpr { pub fn block(&self) -> Option<&Block> { super::child_opt(self) } } // BreakExpr #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct BreakExpr { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for BreakExpr { type Repr = rowan::SyntaxNode; } impl AstNode for BreakExpr { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { BREAK_EXPR => Some(BreakExpr::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl BreakExpr { pub fn expr(&self) -> Option<&Expr> { super::child_opt(self) } } // Byte #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct Byte { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for Byte { type Repr = rowan::SyntaxNode; } impl AstNode for Byte { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { BYTE => Some(Byte::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl ast::AstToken for Byte {} impl Byte {} // ByteString #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct ByteString { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for ByteString { type Repr = rowan::SyntaxNode; } impl AstNode for ByteString { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { BYTE_STRING => Some(ByteString::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl ast::AstToken for ByteString {} impl ByteString {} // CallExpr #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct CallExpr { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for CallExpr { type Repr = rowan::SyntaxNode; } impl AstNode for CallExpr { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { CALL_EXPR => Some(CallExpr::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl ast::ArgListOwner for CallExpr {} impl CallExpr { pub fn expr(&self) -> Option<&Expr> { super::child_opt(self) } } // CastExpr #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct CastExpr { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for CastExpr { type Repr = rowan::SyntaxNode; } impl AstNode for CastExpr { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { CAST_EXPR => Some(CastExpr::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl CastExpr { pub fn expr(&self) -> Option<&Expr> { super::child_opt(self) } pub fn type_ref(&self) -> Option<&TypeRef> { super::child_opt(self) } } // Char #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct Char { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for Char { type Repr = rowan::SyntaxNode; } impl AstNode for Char { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { CHAR => Some(Char::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl ast::AstToken for Char {} impl Char {} // Comment #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct Comment { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for Comment { type Repr = rowan::SyntaxNode; } impl AstNode for Comment { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { COMMENT => Some(Comment::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl ast::AstToken for Comment {} impl Comment {} // Condition #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct Condition { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for Condition { type Repr = rowan::SyntaxNode; } impl AstNode for Condition { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { CONDITION => Some(Condition::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl Condition { pub fn pat(&self) -> Option<&Pat> { super::child_opt(self) } pub fn expr(&self) -> Option<&Expr> { super::child_opt(self) } } // ConstDef #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct ConstDef { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for ConstDef { type Repr = rowan::SyntaxNode; } impl AstNode for ConstDef { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { CONST_DEF => Some(ConstDef::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl ast::VisibilityOwner for ConstDef {} impl ast::NameOwner for ConstDef {} impl ast::TypeParamsOwner for ConstDef {} impl ast::AttrsOwner for ConstDef {} impl ast::DocCommentsOwner for ConstDef {} impl ConstDef { pub fn type_ref(&self) -> Option<&TypeRef> { super::child_opt(self) } } // ContinueExpr #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct ContinueExpr { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for ContinueExpr { type Repr = rowan::SyntaxNode; } impl AstNode for ContinueExpr { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { CONTINUE_EXPR => Some(ContinueExpr::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl ContinueExpr {} // DynTraitType #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct DynTraitType { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for DynTraitType { type Repr = rowan::SyntaxNode; } impl AstNode for DynTraitType { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { DYN_TRAIT_TYPE => Some(DynTraitType::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl DynTraitType {} // EnumDef #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct EnumDef { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for EnumDef { type Repr = rowan::SyntaxNode; } impl AstNode for EnumDef { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { ENUM_DEF => Some(EnumDef::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl ast::VisibilityOwner for EnumDef {} impl ast::NameOwner for EnumDef {} impl ast::TypeParamsOwner for EnumDef {} impl ast::AttrsOwner for EnumDef {} impl ast::DocCommentsOwner for EnumDef {} impl EnumDef { pub fn variant_list(&self) -> Option<&EnumVariantList> { super::child_opt(self) } } // EnumVariant #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct EnumVariant { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for EnumVariant { type Repr = rowan::SyntaxNode; } impl AstNode for EnumVariant { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { ENUM_VARIANT => Some(EnumVariant::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl ast::NameOwner for EnumVariant {} impl ast::DocCommentsOwner for EnumVariant {} impl EnumVariant { pub fn expr(&self) -> Option<&Expr> { super::child_opt(self) } } // EnumVariantList #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct EnumVariantList { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for EnumVariantList { type Repr = rowan::SyntaxNode; } impl AstNode for EnumVariantList { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { ENUM_VARIANT_LIST => Some(EnumVariantList::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl EnumVariantList { pub fn variants(&self) -> impl Iterator { super::children(self) } } // Expr #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct Expr { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for Expr { type Repr = rowan::SyntaxNode; } #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum ExprKind<'a> { TupleExpr(&'a TupleExpr), ArrayExpr(&'a ArrayExpr), ParenExpr(&'a ParenExpr), PathExpr(&'a PathExpr), LambdaExpr(&'a LambdaExpr), IfExpr(&'a IfExpr), LoopExpr(&'a LoopExpr), ForExpr(&'a ForExpr), WhileExpr(&'a WhileExpr), ContinueExpr(&'a ContinueExpr), BreakExpr(&'a BreakExpr), Label(&'a Label), BlockExpr(&'a BlockExpr), ReturnExpr(&'a ReturnExpr), MatchExpr(&'a MatchExpr), StructLit(&'a StructLit), CallExpr(&'a CallExpr), IndexExpr(&'a IndexExpr), MethodCallExpr(&'a MethodCallExpr), FieldExpr(&'a FieldExpr), TryExpr(&'a TryExpr), CastExpr(&'a CastExpr), RefExpr(&'a RefExpr), PrefixExpr(&'a PrefixExpr), RangeExpr(&'a RangeExpr), BinExpr(&'a BinExpr), Literal(&'a Literal), } impl AstNode for Expr { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { | TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | STRUCT_LIT | CALL_EXPR | INDEX_EXPR | METHOD_CALL_EXPR | FIELD_EXPR | TRY_EXPR | CAST_EXPR | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL => Some(Expr::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl Expr { pub fn kind(&self) -> ExprKind { match self.syntax.kind() { TUPLE_EXPR => ExprKind::TupleExpr(TupleExpr::cast(&self.syntax).unwrap()), ARRAY_EXPR => ExprKind::ArrayExpr(ArrayExpr::cast(&self.syntax).unwrap()), PAREN_EXPR => ExprKind::ParenExpr(ParenExpr::cast(&self.syntax).unwrap()), PATH_EXPR => ExprKind::PathExpr(PathExpr::cast(&self.syntax).unwrap()), LAMBDA_EXPR => ExprKind::LambdaExpr(LambdaExpr::cast(&self.syntax).unwrap()), IF_EXPR => ExprKind::IfExpr(IfExpr::cast(&self.syntax).unwrap()), LOOP_EXPR => ExprKind::LoopExpr(LoopExpr::cast(&self.syntax).unwrap()), FOR_EXPR => ExprKind::ForExpr(ForExpr::cast(&self.syntax).unwrap()), WHILE_EXPR => ExprKind::WhileExpr(WhileExpr::cast(&self.syntax).unwrap()), CONTINUE_EXPR => ExprKind::ContinueExpr(ContinueExpr::cast(&self.syntax).unwrap()), BREAK_EXPR => ExprKind::BreakExpr(BreakExpr::cast(&self.syntax).unwrap()), LABEL => ExprKind::Label(Label::cast(&self.syntax).unwrap()), BLOCK_EXPR => ExprKind::BlockExpr(BlockExpr::cast(&self.syntax).unwrap()), RETURN_EXPR => ExprKind::ReturnExpr(ReturnExpr::cast(&self.syntax).unwrap()), MATCH_EXPR => ExprKind::MatchExpr(MatchExpr::cast(&self.syntax).unwrap()), STRUCT_LIT => ExprKind::StructLit(StructLit::cast(&self.syntax).unwrap()), CALL_EXPR => ExprKind::CallExpr(CallExpr::cast(&self.syntax).unwrap()), INDEX_EXPR => ExprKind::IndexExpr(IndexExpr::cast(&self.syntax).unwrap()), METHOD_CALL_EXPR => ExprKind::MethodCallExpr(MethodCallExpr::cast(&self.syntax).unwrap()), FIELD_EXPR => ExprKind::FieldExpr(FieldExpr::cast(&self.syntax).unwrap()), TRY_EXPR => ExprKind::TryExpr(TryExpr::cast(&self.syntax).unwrap()), CAST_EXPR => ExprKind::CastExpr(CastExpr::cast(&self.syntax).unwrap()), REF_EXPR => ExprKind::RefExpr(RefExpr::cast(&self.syntax).unwrap()), PREFIX_EXPR => ExprKind::PrefixExpr(PrefixExpr::cast(&self.syntax).unwrap()), RANGE_EXPR => ExprKind::RangeExpr(RangeExpr::cast(&self.syntax).unwrap()), BIN_EXPR => ExprKind::BinExpr(BinExpr::cast(&self.syntax).unwrap()), LITERAL => ExprKind::Literal(Literal::cast(&self.syntax).unwrap()), _ => unreachable!(), } } } impl Expr {} // ExprStmt #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct ExprStmt { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for ExprStmt { type Repr = rowan::SyntaxNode; } impl AstNode for ExprStmt { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { EXPR_STMT => Some(ExprStmt::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl ExprStmt { pub fn expr(&self) -> Option<&Expr> { super::child_opt(self) } } // ExternCrateItem #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct ExternCrateItem { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for ExternCrateItem { type Repr = rowan::SyntaxNode; } impl AstNode for ExternCrateItem { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { EXTERN_CRATE_ITEM => Some(ExternCrateItem::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl ExternCrateItem {} // FalseKw #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct FalseKw { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for FalseKw { type Repr = rowan::SyntaxNode; } impl AstNode for FalseKw { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { FALSE_KW => Some(FalseKw::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl ast::AstToken for FalseKw {} impl FalseKw {} // FieldExpr #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct FieldExpr { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for FieldExpr { type Repr = rowan::SyntaxNode; } impl AstNode for FieldExpr { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { FIELD_EXPR => Some(FieldExpr::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl FieldExpr { pub fn expr(&self) -> Option<&Expr> { super::child_opt(self) } pub fn name_ref(&self) -> Option<&NameRef> { super::child_opt(self) } } // FieldPat #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct FieldPat { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for FieldPat { type Repr = rowan::SyntaxNode; } impl AstNode for FieldPat { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { FIELD_PAT => Some(FieldPat::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl ast::NameOwner for FieldPat {} impl FieldPat { pub fn pat(&self) -> Option<&Pat> { super::child_opt(self) } } // FieldPatList #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct FieldPatList { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for FieldPatList { type Repr = rowan::SyntaxNode; } impl AstNode for FieldPatList { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { FIELD_PAT_LIST => Some(FieldPatList::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl FieldPatList { pub fn field_pats(&self) -> impl Iterator { super::children(self) } pub fn bind_pats(&self) -> impl Iterator { super::children(self) } } // FloatNumber #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct FloatNumber { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for FloatNumber { type Repr = rowan::SyntaxNode; } impl AstNode for FloatNumber { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { FLOAT_NUMBER => Some(FloatNumber::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl ast::AstToken for FloatNumber {} impl FloatNumber {} // FnDef #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct FnDef { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for FnDef { type Repr = rowan::SyntaxNode; } impl AstNode for FnDef { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { FN_DEF => Some(FnDef::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl ast::VisibilityOwner for FnDef {} impl ast::NameOwner for FnDef {} impl ast::TypeParamsOwner for FnDef {} impl ast::AttrsOwner for FnDef {} impl ast::DocCommentsOwner for FnDef {} impl FnDef { pub fn param_list(&self) -> Option<&ParamList> { super::child_opt(self) } pub fn body(&self) -> Option<&Block> { super::child_opt(self) } pub fn ret_type(&self) -> Option<&RetType> { super::child_opt(self) } } // FnPointerType #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct FnPointerType { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for FnPointerType { type Repr = rowan::SyntaxNode; } impl AstNode for FnPointerType { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { FN_POINTER_TYPE => Some(FnPointerType::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl FnPointerType { pub fn param_list(&self) -> Option<&ParamList> { super::child_opt(self) } pub fn ret_type(&self) -> Option<&RetType> { super::child_opt(self) } } // ForExpr #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct ForExpr { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for ForExpr { type Repr = rowan::SyntaxNode; } impl AstNode for ForExpr { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { FOR_EXPR => Some(ForExpr::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl ast::LoopBodyOwner for ForExpr {} impl ForExpr { pub fn pat(&self) -> Option<&Pat> { super::child_opt(self) } pub fn iterable(&self) -> Option<&Expr> { super::child_opt(self) } } // ForType #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct ForType { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for ForType { type Repr = rowan::SyntaxNode; } impl AstNode for ForType { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { FOR_TYPE => Some(ForType::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl ForType { pub fn type_ref(&self) -> Option<&TypeRef> { super::child_opt(self) } } // IfExpr #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct IfExpr { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for IfExpr { type Repr = rowan::SyntaxNode; } impl AstNode for IfExpr { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { IF_EXPR => Some(IfExpr::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl IfExpr { pub fn condition(&self) -> Option<&Condition> { super::child_opt(self) } } // ImplBlock #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct ImplBlock { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for ImplBlock { type Repr = rowan::SyntaxNode; } impl AstNode for ImplBlock { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { IMPL_BLOCK => Some(ImplBlock::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl ImplBlock { pub fn item_list(&self) -> Option<&ItemList> { super::child_opt(self) } } // ImplItem #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct ImplItem { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for ImplItem { type Repr = rowan::SyntaxNode; } #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum ImplItemKind<'a> { FnDef(&'a FnDef), TypeDef(&'a TypeDef), ConstDef(&'a ConstDef), } impl AstNode for ImplItem { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { | FN_DEF | TYPE_DEF | CONST_DEF => Some(ImplItem::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl ImplItem { pub fn kind(&self) -> ImplItemKind { match self.syntax.kind() { FN_DEF => ImplItemKind::FnDef(FnDef::cast(&self.syntax).unwrap()), TYPE_DEF => ImplItemKind::TypeDef(TypeDef::cast(&self.syntax).unwrap()), CONST_DEF => ImplItemKind::ConstDef(ConstDef::cast(&self.syntax).unwrap()), _ => unreachable!(), } } } impl ImplItem {} // ImplTraitType #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct ImplTraitType { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for ImplTraitType { type Repr = rowan::SyntaxNode; } impl AstNode for ImplTraitType { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { IMPL_TRAIT_TYPE => Some(ImplTraitType::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl ImplTraitType {} // IndexExpr #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct IndexExpr { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for IndexExpr { type Repr = rowan::SyntaxNode; } impl AstNode for IndexExpr { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { INDEX_EXPR => Some(IndexExpr::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl IndexExpr {} // IntNumber #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct IntNumber { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for IntNumber { type Repr = rowan::SyntaxNode; } impl AstNode for IntNumber { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { INT_NUMBER => Some(IntNumber::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl ast::AstToken for IntNumber {} impl IntNumber {} // ItemList #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct ItemList { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for ItemList { type Repr = rowan::SyntaxNode; } impl AstNode for ItemList { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { ITEM_LIST => Some(ItemList::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } impl ast::FnDefOwner for ItemList {} impl ast::ModuleItemOwner for ItemList {} impl ItemList { pub fn impl_items(&self) -> impl Iterator { super::children(self) } } // Label #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct Label { pub(crate) syntax: SyntaxNode, } unsafe impl TransparentNewType for Label { type Repr = rowan::SyntaxNode; } impl AstNode for Label { fn cast(syntax: &SyntaxNode) -> Option<&Self> { match syntax.kind() { LABEL => Some(Label::from_repr(syntax.into_repr())), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } fn to_owned(&self) -> TreeArc