1 // This file is automatically generated based on the file `./generated.rs.tera` when `cargo gen-syntax` is run
2 // Do not edit manually
4 //! This module contains auto-generated Rust AST. Like `SyntaxNode`s, AST nodes
5 //! are generic over ownership: `X<'a>` things are `Copy` references, `XNode`
6 //! are Arc-based. You can switch between the two variants using `.owned` and
7 //! `.borrowed` functions. Most of the code works with borowed mode, and only
8 //! this mode has all AST accessors.
10 #![cfg_attr(rustfmt, rustfmt_skip)]
13 SyntaxNode, SyntaxKind::{self, *},
18 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
20 pub(crate) syntax: SyntaxNode,
23 impl AstNode for Alias {
24 fn can_cast(kind: SyntaxKind) -> bool {
30 fn cast(syntax: SyntaxNode) -> Option<Self> {
31 if Self::can_cast(syntax.kind()) { Some(Alias { syntax }) } else { None }
33 fn syntax(&self) -> &SyntaxNode { &self.syntax }
37 impl ast::NameOwner for Alias {}
41 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
43 pub(crate) syntax: SyntaxNode,
46 impl AstNode for ArgList {
47 fn can_cast(kind: SyntaxKind) -> bool {
53 fn cast(syntax: SyntaxNode) -> Option<Self> {
54 if Self::can_cast(syntax.kind()) { Some(ArgList { syntax }) } else { None }
56 fn syntax(&self) -> &SyntaxNode { &self.syntax }
61 pub fn args(&self) -> impl Iterator<Item = Expr> {
67 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
68 pub struct ArrayExpr {
69 pub(crate) syntax: SyntaxNode,
72 impl AstNode for ArrayExpr {
73 fn can_cast(kind: SyntaxKind) -> bool {
79 fn cast(syntax: SyntaxNode) -> Option<Self> {
80 if Self::can_cast(syntax.kind()) { Some(ArrayExpr { syntax }) } else { None }
82 fn syntax(&self) -> &SyntaxNode { &self.syntax }
87 pub fn exprs(&self) -> impl Iterator<Item = Expr> {
93 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
94 pub struct ArrayType {
95 pub(crate) syntax: SyntaxNode,
98 impl AstNode for ArrayType {
99 fn can_cast(kind: SyntaxKind) -> bool {
105 fn cast(syntax: SyntaxNode) -> Option<Self> {
106 if Self::can_cast(syntax.kind()) { Some(ArrayType { syntax }) } else { None }
108 fn syntax(&self) -> &SyntaxNode { &self.syntax }
113 pub fn type_ref(&self) -> Option<TypeRef> {
114 super::child_opt(self)
117 pub fn expr(&self) -> Option<Expr> {
118 super::child_opt(self)
123 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
124 pub struct AssocTypeArg {
125 pub(crate) syntax: SyntaxNode,
128 impl AstNode for AssocTypeArg {
129 fn can_cast(kind: SyntaxKind) -> bool {
131 ASSOC_TYPE_ARG => true,
135 fn cast(syntax: SyntaxNode) -> Option<Self> {
136 if Self::can_cast(syntax.kind()) { Some(AssocTypeArg { syntax }) } else { None }
138 fn syntax(&self) -> &SyntaxNode { &self.syntax }
143 pub fn name_ref(&self) -> Option<NameRef> {
144 super::child_opt(self)
147 pub fn type_ref(&self) -> Option<TypeRef> {
148 super::child_opt(self)
153 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
155 pub(crate) syntax: SyntaxNode,
158 impl AstNode for Attr {
159 fn can_cast(kind: SyntaxKind) -> bool {
165 fn cast(syntax: SyntaxNode) -> Option<Self> {
166 if Self::can_cast(syntax.kind()) { Some(Attr { syntax }) } else { None }
168 fn syntax(&self) -> &SyntaxNode { &self.syntax }
173 pub fn value(&self) -> Option<TokenTree> {
174 super::child_opt(self)
179 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
181 pub(crate) syntax: SyntaxNode,
184 impl AstNode for BinExpr {
185 fn can_cast(kind: SyntaxKind) -> bool {
191 fn cast(syntax: SyntaxNode) -> Option<Self> {
192 if Self::can_cast(syntax.kind()) { Some(BinExpr { syntax }) } else { None }
194 fn syntax(&self) -> &SyntaxNode { &self.syntax }
201 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
203 pub(crate) syntax: SyntaxNode,
206 impl AstNode for BindPat {
207 fn can_cast(kind: SyntaxKind) -> bool {
213 fn cast(syntax: SyntaxNode) -> Option<Self> {
214 if Self::can_cast(syntax.kind()) { Some(BindPat { syntax }) } else { None }
216 fn syntax(&self) -> &SyntaxNode { &self.syntax }
220 impl ast::NameOwner for BindPat {}
222 pub fn pat(&self) -> Option<Pat> {
223 super::child_opt(self)
228 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
230 pub(crate) syntax: SyntaxNode,
233 impl AstNode for Block {
234 fn can_cast(kind: SyntaxKind) -> bool {
240 fn cast(syntax: SyntaxNode) -> Option<Self> {
241 if Self::can_cast(syntax.kind()) { Some(Block { syntax }) } else { None }
243 fn syntax(&self) -> &SyntaxNode { &self.syntax }
247 impl ast::AttrsOwner for Block {}
249 pub fn statements(&self) -> impl Iterator<Item = Stmt> {
250 super::children(self)
253 pub fn expr(&self) -> Option<Expr> {
254 super::child_opt(self)
259 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
260 pub struct BlockExpr {
261 pub(crate) syntax: SyntaxNode,
264 impl AstNode for BlockExpr {
265 fn can_cast(kind: SyntaxKind) -> bool {
271 fn cast(syntax: SyntaxNode) -> Option<Self> {
272 if Self::can_cast(syntax.kind()) { Some(BlockExpr { syntax }) } else { None }
274 fn syntax(&self) -> &SyntaxNode { &self.syntax }
279 pub fn block(&self) -> Option<Block> {
280 super::child_opt(self)
285 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
286 pub struct BreakExpr {
287 pub(crate) syntax: SyntaxNode,
290 impl AstNode for BreakExpr {
291 fn can_cast(kind: SyntaxKind) -> bool {
297 fn cast(syntax: SyntaxNode) -> Option<Self> {
298 if Self::can_cast(syntax.kind()) { Some(BreakExpr { syntax }) } else { None }
300 fn syntax(&self) -> &SyntaxNode { &self.syntax }
305 pub fn expr(&self) -> Option<Expr> {
306 super::child_opt(self)
311 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
312 pub struct CallExpr {
313 pub(crate) syntax: SyntaxNode,
316 impl AstNode for CallExpr {
317 fn can_cast(kind: SyntaxKind) -> bool {
323 fn cast(syntax: SyntaxNode) -> Option<Self> {
324 if Self::can_cast(syntax.kind()) { Some(CallExpr { syntax }) } else { None }
326 fn syntax(&self) -> &SyntaxNode { &self.syntax }
330 impl ast::ArgListOwner for CallExpr {}
332 pub fn expr(&self) -> Option<Expr> {
333 super::child_opt(self)
338 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
339 pub struct CastExpr {
340 pub(crate) syntax: SyntaxNode,
343 impl AstNode for CastExpr {
344 fn can_cast(kind: SyntaxKind) -> bool {
350 fn cast(syntax: SyntaxNode) -> Option<Self> {
351 if Self::can_cast(syntax.kind()) { Some(CastExpr { syntax }) } else { None }
353 fn syntax(&self) -> &SyntaxNode { &self.syntax }
358 pub fn expr(&self) -> Option<Expr> {
359 super::child_opt(self)
362 pub fn type_ref(&self) -> Option<TypeRef> {
363 super::child_opt(self)
368 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
369 pub struct Condition {
370 pub(crate) syntax: SyntaxNode,
373 impl AstNode for Condition {
374 fn can_cast(kind: SyntaxKind) -> bool {
380 fn cast(syntax: SyntaxNode) -> Option<Self> {
381 if Self::can_cast(syntax.kind()) { Some(Condition { syntax }) } else { None }
383 fn syntax(&self) -> &SyntaxNode { &self.syntax }
388 pub fn pat(&self) -> Option<Pat> {
389 super::child_opt(self)
392 pub fn expr(&self) -> Option<Expr> {
393 super::child_opt(self)
398 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
399 pub struct ConstDef {
400 pub(crate) syntax: SyntaxNode,
403 impl AstNode for ConstDef {
404 fn can_cast(kind: SyntaxKind) -> bool {
410 fn cast(syntax: SyntaxNode) -> Option<Self> {
411 if Self::can_cast(syntax.kind()) { Some(ConstDef { syntax }) } else { None }
413 fn syntax(&self) -> &SyntaxNode { &self.syntax }
417 impl ast::VisibilityOwner for ConstDef {}
418 impl ast::NameOwner for ConstDef {}
419 impl ast::TypeParamsOwner for ConstDef {}
420 impl ast::AttrsOwner for ConstDef {}
421 impl ast::DocCommentsOwner for ConstDef {}
422 impl ast::TypeAscriptionOwner for ConstDef {}
424 pub fn body(&self) -> Option<Expr> {
425 super::child_opt(self)
430 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
431 pub struct ContinueExpr {
432 pub(crate) syntax: SyntaxNode,
435 impl AstNode for ContinueExpr {
436 fn can_cast(kind: SyntaxKind) -> bool {
438 CONTINUE_EXPR => true,
442 fn cast(syntax: SyntaxNode) -> Option<Self> {
443 if Self::can_cast(syntax.kind()) { Some(ContinueExpr { syntax }) } else { None }
445 fn syntax(&self) -> &SyntaxNode { &self.syntax }
452 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
453 pub struct DynTraitType {
454 pub(crate) syntax: SyntaxNode,
457 impl AstNode for DynTraitType {
458 fn can_cast(kind: SyntaxKind) -> bool {
460 DYN_TRAIT_TYPE => true,
464 fn cast(syntax: SyntaxNode) -> Option<Self> {
465 if Self::can_cast(syntax.kind()) { Some(DynTraitType { syntax }) } else { None }
467 fn syntax(&self) -> &SyntaxNode { &self.syntax }
471 impl ast::TypeBoundsOwner for DynTraitType {}
475 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
477 pub(crate) syntax: SyntaxNode,
480 impl AstNode for EnumDef {
481 fn can_cast(kind: SyntaxKind) -> bool {
487 fn cast(syntax: SyntaxNode) -> Option<Self> {
488 if Self::can_cast(syntax.kind()) { Some(EnumDef { syntax }) } else { None }
490 fn syntax(&self) -> &SyntaxNode { &self.syntax }
494 impl ast::VisibilityOwner for EnumDef {}
495 impl ast::NameOwner for EnumDef {}
496 impl ast::TypeParamsOwner for EnumDef {}
497 impl ast::AttrsOwner for EnumDef {}
498 impl ast::DocCommentsOwner for EnumDef {}
500 pub fn variant_list(&self) -> Option<EnumVariantList> {
501 super::child_opt(self)
506 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
507 pub struct EnumVariant {
508 pub(crate) syntax: SyntaxNode,
511 impl AstNode for EnumVariant {
512 fn can_cast(kind: SyntaxKind) -> bool {
514 ENUM_VARIANT => true,
518 fn cast(syntax: SyntaxNode) -> Option<Self> {
519 if Self::can_cast(syntax.kind()) { Some(EnumVariant { syntax }) } else { None }
521 fn syntax(&self) -> &SyntaxNode { &self.syntax }
525 impl ast::NameOwner for EnumVariant {}
526 impl ast::DocCommentsOwner for EnumVariant {}
527 impl ast::AttrsOwner for EnumVariant {}
529 pub fn expr(&self) -> Option<Expr> {
530 super::child_opt(self)
535 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
536 pub struct EnumVariantList {
537 pub(crate) syntax: SyntaxNode,
540 impl AstNode for EnumVariantList {
541 fn can_cast(kind: SyntaxKind) -> bool {
543 ENUM_VARIANT_LIST => true,
547 fn cast(syntax: SyntaxNode) -> Option<Self> {
548 if Self::can_cast(syntax.kind()) { Some(EnumVariantList { syntax }) } else { None }
550 fn syntax(&self) -> &SyntaxNode { &self.syntax }
554 impl EnumVariantList {
555 pub fn variants(&self) -> impl Iterator<Item = EnumVariant> {
556 super::children(self)
561 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
563 pub(crate) syntax: SyntaxNode,
566 impl AstNode for Expr {
567 fn can_cast(kind: SyntaxKind) -> bool {
569 | 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 | TRY_BLOCK_EXPR | CAST_EXPR | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL => true,
573 fn cast(syntax: SyntaxNode) -> Option<Self> {
574 if Self::can_cast(syntax.kind()) { Some(Expr { syntax }) } else { None }
576 fn syntax(&self) -> &SyntaxNode { &self.syntax }
580 #[derive(Debug, Clone, PartialEq, Eq)]
582 TupleExpr(TupleExpr),
583 ArrayExpr(ArrayExpr),
584 ParenExpr(ParenExpr),
586 LambdaExpr(LambdaExpr),
590 WhileExpr(WhileExpr),
591 ContinueExpr(ContinueExpr),
592 BreakExpr(BreakExpr),
594 BlockExpr(BlockExpr),
595 ReturnExpr(ReturnExpr),
596 MatchExpr(MatchExpr),
597 StructLit(StructLit),
599 IndexExpr(IndexExpr),
600 MethodCallExpr(MethodCallExpr),
601 FieldExpr(FieldExpr),
603 TryBlockExpr(TryBlockExpr),
606 PrefixExpr(PrefixExpr),
607 RangeExpr(RangeExpr),
610 MacroCall(MacroCall),
612 impl From<TupleExpr> for Expr {
613 fn from(n: TupleExpr) -> Expr { Expr { syntax: n.syntax } }
615 impl From<ArrayExpr> for Expr {
616 fn from(n: ArrayExpr) -> Expr { Expr { syntax: n.syntax } }
618 impl From<ParenExpr> for Expr {
619 fn from(n: ParenExpr) -> Expr { Expr { syntax: n.syntax } }
621 impl From<PathExpr> for Expr {
622 fn from(n: PathExpr) -> Expr { Expr { syntax: n.syntax } }
624 impl From<LambdaExpr> for Expr {
625 fn from(n: LambdaExpr) -> Expr { Expr { syntax: n.syntax } }
627 impl From<IfExpr> for Expr {
628 fn from(n: IfExpr) -> Expr { Expr { syntax: n.syntax } }
630 impl From<LoopExpr> for Expr {
631 fn from(n: LoopExpr) -> Expr { Expr { syntax: n.syntax } }
633 impl From<ForExpr> for Expr {
634 fn from(n: ForExpr) -> Expr { Expr { syntax: n.syntax } }
636 impl From<WhileExpr> for Expr {
637 fn from(n: WhileExpr) -> Expr { Expr { syntax: n.syntax } }
639 impl From<ContinueExpr> for Expr {
640 fn from(n: ContinueExpr) -> Expr { Expr { syntax: n.syntax } }
642 impl From<BreakExpr> for Expr {
643 fn from(n: BreakExpr) -> Expr { Expr { syntax: n.syntax } }
645 impl From<Label> for Expr {
646 fn from(n: Label) -> Expr { Expr { syntax: n.syntax } }
648 impl From<BlockExpr> for Expr {
649 fn from(n: BlockExpr) -> Expr { Expr { syntax: n.syntax } }
651 impl From<ReturnExpr> for Expr {
652 fn from(n: ReturnExpr) -> Expr { Expr { syntax: n.syntax } }
654 impl From<MatchExpr> for Expr {
655 fn from(n: MatchExpr) -> Expr { Expr { syntax: n.syntax } }
657 impl From<StructLit> for Expr {
658 fn from(n: StructLit) -> Expr { Expr { syntax: n.syntax } }
660 impl From<CallExpr> for Expr {
661 fn from(n: CallExpr) -> Expr { Expr { syntax: n.syntax } }
663 impl From<IndexExpr> for Expr {
664 fn from(n: IndexExpr) -> Expr { Expr { syntax: n.syntax } }
666 impl From<MethodCallExpr> for Expr {
667 fn from(n: MethodCallExpr) -> Expr { Expr { syntax: n.syntax } }
669 impl From<FieldExpr> for Expr {
670 fn from(n: FieldExpr) -> Expr { Expr { syntax: n.syntax } }
672 impl From<TryExpr> for Expr {
673 fn from(n: TryExpr) -> Expr { Expr { syntax: n.syntax } }
675 impl From<TryBlockExpr> for Expr {
676 fn from(n: TryBlockExpr) -> Expr { Expr { syntax: n.syntax } }
678 impl From<CastExpr> for Expr {
679 fn from(n: CastExpr) -> Expr { Expr { syntax: n.syntax } }
681 impl From<RefExpr> for Expr {
682 fn from(n: RefExpr) -> Expr { Expr { syntax: n.syntax } }
684 impl From<PrefixExpr> for Expr {
685 fn from(n: PrefixExpr) -> Expr { Expr { syntax: n.syntax } }
687 impl From<RangeExpr> for Expr {
688 fn from(n: RangeExpr) -> Expr { Expr { syntax: n.syntax } }
690 impl From<BinExpr> for Expr {
691 fn from(n: BinExpr) -> Expr { Expr { syntax: n.syntax } }
693 impl From<Literal> for Expr {
694 fn from(n: Literal) -> Expr { Expr { syntax: n.syntax } }
696 impl From<MacroCall> for Expr {
697 fn from(n: MacroCall) -> Expr { Expr { syntax: n.syntax } }
700 pub fn kind(&self) -> ExprKind {
701 match self.syntax.kind() {
702 TUPLE_EXPR => ExprKind::TupleExpr(TupleExpr::cast(self.syntax.clone()).unwrap()),
703 ARRAY_EXPR => ExprKind::ArrayExpr(ArrayExpr::cast(self.syntax.clone()).unwrap()),
704 PAREN_EXPR => ExprKind::ParenExpr(ParenExpr::cast(self.syntax.clone()).unwrap()),
705 PATH_EXPR => ExprKind::PathExpr(PathExpr::cast(self.syntax.clone()).unwrap()),
706 LAMBDA_EXPR => ExprKind::LambdaExpr(LambdaExpr::cast(self.syntax.clone()).unwrap()),
707 IF_EXPR => ExprKind::IfExpr(IfExpr::cast(self.syntax.clone()).unwrap()),
708 LOOP_EXPR => ExprKind::LoopExpr(LoopExpr::cast(self.syntax.clone()).unwrap()),
709 FOR_EXPR => ExprKind::ForExpr(ForExpr::cast(self.syntax.clone()).unwrap()),
710 WHILE_EXPR => ExprKind::WhileExpr(WhileExpr::cast(self.syntax.clone()).unwrap()),
711 CONTINUE_EXPR => ExprKind::ContinueExpr(ContinueExpr::cast(self.syntax.clone()).unwrap()),
712 BREAK_EXPR => ExprKind::BreakExpr(BreakExpr::cast(self.syntax.clone()).unwrap()),
713 LABEL => ExprKind::Label(Label::cast(self.syntax.clone()).unwrap()),
714 BLOCK_EXPR => ExprKind::BlockExpr(BlockExpr::cast(self.syntax.clone()).unwrap()),
715 RETURN_EXPR => ExprKind::ReturnExpr(ReturnExpr::cast(self.syntax.clone()).unwrap()),
716 MATCH_EXPR => ExprKind::MatchExpr(MatchExpr::cast(self.syntax.clone()).unwrap()),
717 STRUCT_LIT => ExprKind::StructLit(StructLit::cast(self.syntax.clone()).unwrap()),
718 CALL_EXPR => ExprKind::CallExpr(CallExpr::cast(self.syntax.clone()).unwrap()),
719 INDEX_EXPR => ExprKind::IndexExpr(IndexExpr::cast(self.syntax.clone()).unwrap()),
720 METHOD_CALL_EXPR => ExprKind::MethodCallExpr(MethodCallExpr::cast(self.syntax.clone()).unwrap()),
721 FIELD_EXPR => ExprKind::FieldExpr(FieldExpr::cast(self.syntax.clone()).unwrap()),
722 TRY_EXPR => ExprKind::TryExpr(TryExpr::cast(self.syntax.clone()).unwrap()),
723 TRY_BLOCK_EXPR => ExprKind::TryBlockExpr(TryBlockExpr::cast(self.syntax.clone()).unwrap()),
724 CAST_EXPR => ExprKind::CastExpr(CastExpr::cast(self.syntax.clone()).unwrap()),
725 REF_EXPR => ExprKind::RefExpr(RefExpr::cast(self.syntax.clone()).unwrap()),
726 PREFIX_EXPR => ExprKind::PrefixExpr(PrefixExpr::cast(self.syntax.clone()).unwrap()),
727 RANGE_EXPR => ExprKind::RangeExpr(RangeExpr::cast(self.syntax.clone()).unwrap()),
728 BIN_EXPR => ExprKind::BinExpr(BinExpr::cast(self.syntax.clone()).unwrap()),
729 LITERAL => ExprKind::Literal(Literal::cast(self.syntax.clone()).unwrap()),
730 MACRO_CALL => ExprKind::MacroCall(MacroCall::cast(self.syntax.clone()).unwrap()),
739 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
740 pub struct ExprStmt {
741 pub(crate) syntax: SyntaxNode,
744 impl AstNode for ExprStmt {
745 fn can_cast(kind: SyntaxKind) -> bool {
751 fn cast(syntax: SyntaxNode) -> Option<Self> {
752 if Self::can_cast(syntax.kind()) { Some(ExprStmt { syntax }) } else { None }
754 fn syntax(&self) -> &SyntaxNode { &self.syntax }
759 pub fn expr(&self) -> Option<Expr> {
760 super::child_opt(self)
765 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
766 pub struct ExternCrateItem {
767 pub(crate) syntax: SyntaxNode,
770 impl AstNode for ExternCrateItem {
771 fn can_cast(kind: SyntaxKind) -> bool {
773 EXTERN_CRATE_ITEM => true,
777 fn cast(syntax: SyntaxNode) -> Option<Self> {
778 if Self::can_cast(syntax.kind()) { Some(ExternCrateItem { syntax }) } else { None }
780 fn syntax(&self) -> &SyntaxNode { &self.syntax }
784 impl ExternCrateItem {
785 pub fn name_ref(&self) -> Option<NameRef> {
786 super::child_opt(self)
789 pub fn alias(&self) -> Option<Alias> {
790 super::child_opt(self)
795 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
796 pub struct FieldExpr {
797 pub(crate) syntax: SyntaxNode,
800 impl AstNode for FieldExpr {
801 fn can_cast(kind: SyntaxKind) -> bool {
807 fn cast(syntax: SyntaxNode) -> Option<Self> {
808 if Self::can_cast(syntax.kind()) { Some(FieldExpr { syntax }) } else { None }
810 fn syntax(&self) -> &SyntaxNode { &self.syntax }
815 pub fn expr(&self) -> Option<Expr> {
816 super::child_opt(self)
819 pub fn name_ref(&self) -> Option<NameRef> {
820 super::child_opt(self)
825 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
826 pub struct FieldPat {
827 pub(crate) syntax: SyntaxNode,
830 impl AstNode for FieldPat {
831 fn can_cast(kind: SyntaxKind) -> bool {
837 fn cast(syntax: SyntaxNode) -> Option<Self> {
838 if Self::can_cast(syntax.kind()) { Some(FieldPat { syntax }) } else { None }
840 fn syntax(&self) -> &SyntaxNode { &self.syntax }
844 impl ast::NameOwner for FieldPat {}
846 pub fn pat(&self) -> Option<Pat> {
847 super::child_opt(self)
852 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
853 pub struct FieldPatList {
854 pub(crate) syntax: SyntaxNode,
857 impl AstNode for FieldPatList {
858 fn can_cast(kind: SyntaxKind) -> bool {
860 FIELD_PAT_LIST => true,
864 fn cast(syntax: SyntaxNode) -> Option<Self> {
865 if Self::can_cast(syntax.kind()) { Some(FieldPatList { syntax }) } else { None }
867 fn syntax(&self) -> &SyntaxNode { &self.syntax }
872 pub fn field_pats(&self) -> impl Iterator<Item = FieldPat> {
873 super::children(self)
876 pub fn bind_pats(&self) -> impl Iterator<Item = BindPat> {
877 super::children(self)
882 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
884 pub(crate) syntax: SyntaxNode,
887 impl AstNode for FnDef {
888 fn can_cast(kind: SyntaxKind) -> bool {
894 fn cast(syntax: SyntaxNode) -> Option<Self> {
895 if Self::can_cast(syntax.kind()) { Some(FnDef { syntax }) } else { None }
897 fn syntax(&self) -> &SyntaxNode { &self.syntax }
901 impl ast::VisibilityOwner for FnDef {}
902 impl ast::NameOwner for FnDef {}
903 impl ast::TypeParamsOwner for FnDef {}
904 impl ast::AttrsOwner for FnDef {}
905 impl ast::DocCommentsOwner for FnDef {}
907 pub fn param_list(&self) -> Option<ParamList> {
908 super::child_opt(self)
911 pub fn body(&self) -> Option<Block> {
912 super::child_opt(self)
915 pub fn ret_type(&self) -> Option<RetType> {
916 super::child_opt(self)
921 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
922 pub struct FnPointerType {
923 pub(crate) syntax: SyntaxNode,
926 impl AstNode for FnPointerType {
927 fn can_cast(kind: SyntaxKind) -> bool {
929 FN_POINTER_TYPE => true,
933 fn cast(syntax: SyntaxNode) -> Option<Self> {
934 if Self::can_cast(syntax.kind()) { Some(FnPointerType { syntax }) } else { None }
936 fn syntax(&self) -> &SyntaxNode { &self.syntax }
941 pub fn param_list(&self) -> Option<ParamList> {
942 super::child_opt(self)
945 pub fn ret_type(&self) -> Option<RetType> {
946 super::child_opt(self)
951 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
953 pub(crate) syntax: SyntaxNode,
956 impl AstNode for ForExpr {
957 fn can_cast(kind: SyntaxKind) -> bool {
963 fn cast(syntax: SyntaxNode) -> Option<Self> {
964 if Self::can_cast(syntax.kind()) { Some(ForExpr { syntax }) } else { None }
966 fn syntax(&self) -> &SyntaxNode { &self.syntax }
970 impl ast::LoopBodyOwner for ForExpr {}
972 pub fn pat(&self) -> Option<Pat> {
973 super::child_opt(self)
976 pub fn iterable(&self) -> Option<Expr> {
977 super::child_opt(self)
982 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
984 pub(crate) syntax: SyntaxNode,
987 impl AstNode for ForType {
988 fn can_cast(kind: SyntaxKind) -> bool {
994 fn cast(syntax: SyntaxNode) -> Option<Self> {
995 if Self::can_cast(syntax.kind()) { Some(ForType { syntax }) } else { None }
997 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1002 pub fn type_ref(&self) -> Option<TypeRef> {
1003 super::child_opt(self)
1008 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1010 pub(crate) syntax: SyntaxNode,
1013 impl AstNode for IfExpr {
1014 fn can_cast(kind: SyntaxKind) -> bool {
1020 fn cast(syntax: SyntaxNode) -> Option<Self> {
1021 if Self::can_cast(syntax.kind()) { Some(IfExpr { syntax }) } else { None }
1023 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1028 pub fn condition(&self) -> Option<Condition> {
1029 super::child_opt(self)
1034 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1035 pub struct ImplBlock {
1036 pub(crate) syntax: SyntaxNode,
1039 impl AstNode for ImplBlock {
1040 fn can_cast(kind: SyntaxKind) -> bool {
1046 fn cast(syntax: SyntaxNode) -> Option<Self> {
1047 if Self::can_cast(syntax.kind()) { Some(ImplBlock { syntax }) } else { None }
1049 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1053 impl ast::TypeParamsOwner for ImplBlock {}
1054 impl ast::AttrsOwner for ImplBlock {}
1056 pub fn item_list(&self) -> Option<ItemList> {
1057 super::child_opt(self)
1062 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1063 pub struct ImplItem {
1064 pub(crate) syntax: SyntaxNode,
1067 impl AstNode for ImplItem {
1068 fn can_cast(kind: SyntaxKind) -> bool {
1070 | FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true,
1074 fn cast(syntax: SyntaxNode) -> Option<Self> {
1075 if Self::can_cast(syntax.kind()) { Some(ImplItem { syntax }) } else { None }
1077 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1081 #[derive(Debug, Clone, PartialEq, Eq)]
1082 pub enum ImplItemKind {
1084 TypeAliasDef(TypeAliasDef),
1087 impl From<FnDef> for ImplItem {
1088 fn from(n: FnDef) -> ImplItem { ImplItem { syntax: n.syntax } }
1090 impl From<TypeAliasDef> for ImplItem {
1091 fn from(n: TypeAliasDef) -> ImplItem { ImplItem { syntax: n.syntax } }
1093 impl From<ConstDef> for ImplItem {
1094 fn from(n: ConstDef) -> ImplItem { ImplItem { syntax: n.syntax } }
1097 pub fn kind(&self) -> ImplItemKind {
1098 match self.syntax.kind() {
1099 FN_DEF => ImplItemKind::FnDef(FnDef::cast(self.syntax.clone()).unwrap()),
1100 TYPE_ALIAS_DEF => ImplItemKind::TypeAliasDef(TypeAliasDef::cast(self.syntax.clone()).unwrap()),
1101 CONST_DEF => ImplItemKind::ConstDef(ConstDef::cast(self.syntax.clone()).unwrap()),
1102 _ => unreachable!(),
1110 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1111 pub struct ImplTraitType {
1112 pub(crate) syntax: SyntaxNode,
1115 impl AstNode for ImplTraitType {
1116 fn can_cast(kind: SyntaxKind) -> bool {
1118 IMPL_TRAIT_TYPE => true,
1122 fn cast(syntax: SyntaxNode) -> Option<Self> {
1123 if Self::can_cast(syntax.kind()) { Some(ImplTraitType { syntax }) } else { None }
1125 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1129 impl ast::TypeBoundsOwner for ImplTraitType {}
1130 impl ImplTraitType {}
1133 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1134 pub struct IndexExpr {
1135 pub(crate) syntax: SyntaxNode,
1138 impl AstNode for IndexExpr {
1139 fn can_cast(kind: SyntaxKind) -> bool {
1145 fn cast(syntax: SyntaxNode) -> Option<Self> {
1146 if Self::can_cast(syntax.kind()) { Some(IndexExpr { syntax }) } else { None }
1148 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1155 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1156 pub struct ItemList {
1157 pub(crate) syntax: SyntaxNode,
1160 impl AstNode for ItemList {
1161 fn can_cast(kind: SyntaxKind) -> bool {
1167 fn cast(syntax: SyntaxNode) -> Option<Self> {
1168 if Self::can_cast(syntax.kind()) { Some(ItemList { syntax }) } else { None }
1170 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1174 impl ast::FnDefOwner for ItemList {}
1175 impl ast::ModuleItemOwner for ItemList {}
1177 pub fn impl_items(&self) -> impl Iterator<Item = ImplItem> {
1178 super::children(self)
1183 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1185 pub(crate) syntax: SyntaxNode,
1188 impl AstNode for Label {
1189 fn can_cast(kind: SyntaxKind) -> bool {
1195 fn cast(syntax: SyntaxNode) -> Option<Self> {
1196 if Self::can_cast(syntax.kind()) { Some(Label { syntax }) } else { None }
1198 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1205 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1206 pub struct LambdaExpr {
1207 pub(crate) syntax: SyntaxNode,
1210 impl AstNode for LambdaExpr {
1211 fn can_cast(kind: SyntaxKind) -> bool {
1213 LAMBDA_EXPR => true,
1217 fn cast(syntax: SyntaxNode) -> Option<Self> {
1218 if Self::can_cast(syntax.kind()) { Some(LambdaExpr { syntax }) } else { None }
1220 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1225 pub fn param_list(&self) -> Option<ParamList> {
1226 super::child_opt(self)
1229 pub fn body(&self) -> Option<Expr> {
1230 super::child_opt(self)
1235 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1236 pub struct LetStmt {
1237 pub(crate) syntax: SyntaxNode,
1240 impl AstNode for LetStmt {
1241 fn can_cast(kind: SyntaxKind) -> bool {
1247 fn cast(syntax: SyntaxNode) -> Option<Self> {
1248 if Self::can_cast(syntax.kind()) { Some(LetStmt { syntax }) } else { None }
1250 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1254 impl ast::TypeAscriptionOwner for LetStmt {}
1256 pub fn pat(&self) -> Option<Pat> {
1257 super::child_opt(self)
1260 pub fn initializer(&self) -> Option<Expr> {
1261 super::child_opt(self)
1266 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1267 pub struct LifetimeArg {
1268 pub(crate) syntax: SyntaxNode,
1271 impl AstNode for LifetimeArg {
1272 fn can_cast(kind: SyntaxKind) -> bool {
1274 LIFETIME_ARG => true,
1278 fn cast(syntax: SyntaxNode) -> Option<Self> {
1279 if Self::can_cast(syntax.kind()) { Some(LifetimeArg { syntax }) } else { None }
1281 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1288 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1289 pub struct LifetimeParam {
1290 pub(crate) syntax: SyntaxNode,
1293 impl AstNode for LifetimeParam {
1294 fn can_cast(kind: SyntaxKind) -> bool {
1296 LIFETIME_PARAM => true,
1300 fn cast(syntax: SyntaxNode) -> Option<Self> {
1301 if Self::can_cast(syntax.kind()) { Some(LifetimeParam { syntax }) } else { None }
1303 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1307 impl ast::AttrsOwner for LifetimeParam {}
1308 impl LifetimeParam {}
1311 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1312 pub struct Literal {
1313 pub(crate) syntax: SyntaxNode,
1316 impl AstNode for Literal {
1317 fn can_cast(kind: SyntaxKind) -> bool {
1323 fn cast(syntax: SyntaxNode) -> Option<Self> {
1324 if Self::can_cast(syntax.kind()) { Some(Literal { syntax }) } else { None }
1326 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1333 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1334 pub struct LiteralPat {
1335 pub(crate) syntax: SyntaxNode,
1338 impl AstNode for LiteralPat {
1339 fn can_cast(kind: SyntaxKind) -> bool {
1341 LITERAL_PAT => true,
1345 fn cast(syntax: SyntaxNode) -> Option<Self> {
1346 if Self::can_cast(syntax.kind()) { Some(LiteralPat { syntax }) } else { None }
1348 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1353 pub fn literal(&self) -> Option<Literal> {
1354 super::child_opt(self)
1359 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1360 pub struct LoopExpr {
1361 pub(crate) syntax: SyntaxNode,
1364 impl AstNode for LoopExpr {
1365 fn can_cast(kind: SyntaxKind) -> bool {
1371 fn cast(syntax: SyntaxNode) -> Option<Self> {
1372 if Self::can_cast(syntax.kind()) { Some(LoopExpr { syntax }) } else { None }
1374 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1378 impl ast::LoopBodyOwner for LoopExpr {}
1382 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1383 pub struct MacroCall {
1384 pub(crate) syntax: SyntaxNode,
1387 impl AstNode for MacroCall {
1388 fn can_cast(kind: SyntaxKind) -> bool {
1394 fn cast(syntax: SyntaxNode) -> Option<Self> {
1395 if Self::can_cast(syntax.kind()) { Some(MacroCall { syntax }) } else { None }
1397 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1401 impl ast::NameOwner for MacroCall {}
1402 impl ast::AttrsOwner for MacroCall {}
1403 impl ast::DocCommentsOwner for MacroCall {}
1405 pub fn token_tree(&self) -> Option<TokenTree> {
1406 super::child_opt(self)
1409 pub fn path(&self) -> Option<Path> {
1410 super::child_opt(self)
1415 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1416 pub struct MacroItems {
1417 pub(crate) syntax: SyntaxNode,
1420 impl AstNode for MacroItems {
1421 fn can_cast(kind: SyntaxKind) -> bool {
1423 MACRO_ITEMS => true,
1427 fn cast(syntax: SyntaxNode) -> Option<Self> {
1428 if Self::can_cast(syntax.kind()) { Some(MacroItems { syntax }) } else { None }
1430 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1434 impl ast::ModuleItemOwner for MacroItems {}
1435 impl ast::FnDefOwner for MacroItems {}
1439 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1440 pub struct MacroStmts {
1441 pub(crate) syntax: SyntaxNode,
1444 impl AstNode for MacroStmts {
1445 fn can_cast(kind: SyntaxKind) -> bool {
1447 MACRO_STMTS => true,
1451 fn cast(syntax: SyntaxNode) -> Option<Self> {
1452 if Self::can_cast(syntax.kind()) { Some(MacroStmts { syntax }) } else { None }
1454 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1459 pub fn statements(&self) -> impl Iterator<Item = Stmt> {
1460 super::children(self)
1463 pub fn expr(&self) -> Option<Expr> {
1464 super::child_opt(self)
1469 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1470 pub struct MatchArm {
1471 pub(crate) syntax: SyntaxNode,
1474 impl AstNode for MatchArm {
1475 fn can_cast(kind: SyntaxKind) -> bool {
1481 fn cast(syntax: SyntaxNode) -> Option<Self> {
1482 if Self::can_cast(syntax.kind()) { Some(MatchArm { syntax }) } else { None }
1484 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1488 impl ast::AttrsOwner for MatchArm {}
1490 pub fn pats(&self) -> impl Iterator<Item = Pat> {
1491 super::children(self)
1494 pub fn guard(&self) -> Option<MatchGuard> {
1495 super::child_opt(self)
1498 pub fn expr(&self) -> Option<Expr> {
1499 super::child_opt(self)
1504 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1505 pub struct MatchArmList {
1506 pub(crate) syntax: SyntaxNode,
1509 impl AstNode for MatchArmList {
1510 fn can_cast(kind: SyntaxKind) -> bool {
1512 MATCH_ARM_LIST => true,
1516 fn cast(syntax: SyntaxNode) -> Option<Self> {
1517 if Self::can_cast(syntax.kind()) { Some(MatchArmList { syntax }) } else { None }
1519 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1523 impl ast::AttrsOwner for MatchArmList {}
1525 pub fn arms(&self) -> impl Iterator<Item = MatchArm> {
1526 super::children(self)
1531 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1532 pub struct MatchExpr {
1533 pub(crate) syntax: SyntaxNode,
1536 impl AstNode for MatchExpr {
1537 fn can_cast(kind: SyntaxKind) -> bool {
1543 fn cast(syntax: SyntaxNode) -> Option<Self> {
1544 if Self::can_cast(syntax.kind()) { Some(MatchExpr { syntax }) } else { None }
1546 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1551 pub fn expr(&self) -> Option<Expr> {
1552 super::child_opt(self)
1555 pub fn match_arm_list(&self) -> Option<MatchArmList> {
1556 super::child_opt(self)
1561 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1562 pub struct MatchGuard {
1563 pub(crate) syntax: SyntaxNode,
1566 impl AstNode for MatchGuard {
1567 fn can_cast(kind: SyntaxKind) -> bool {
1569 MATCH_GUARD => true,
1573 fn cast(syntax: SyntaxNode) -> Option<Self> {
1574 if Self::can_cast(syntax.kind()) { Some(MatchGuard { syntax }) } else { None }
1576 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1581 pub fn expr(&self) -> Option<Expr> {
1582 super::child_opt(self)
1587 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1588 pub struct MethodCallExpr {
1589 pub(crate) syntax: SyntaxNode,
1592 impl AstNode for MethodCallExpr {
1593 fn can_cast(kind: SyntaxKind) -> bool {
1595 METHOD_CALL_EXPR => true,
1599 fn cast(syntax: SyntaxNode) -> Option<Self> {
1600 if Self::can_cast(syntax.kind()) { Some(MethodCallExpr { syntax }) } else { None }
1602 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1606 impl ast::ArgListOwner for MethodCallExpr {}
1607 impl MethodCallExpr {
1608 pub fn expr(&self) -> Option<Expr> {
1609 super::child_opt(self)
1612 pub fn name_ref(&self) -> Option<NameRef> {
1613 super::child_opt(self)
1616 pub fn type_arg_list(&self) -> Option<TypeArgList> {
1617 super::child_opt(self)
1622 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1624 pub(crate) syntax: SyntaxNode,
1627 impl AstNode for Module {
1628 fn can_cast(kind: SyntaxKind) -> bool {
1634 fn cast(syntax: SyntaxNode) -> Option<Self> {
1635 if Self::can_cast(syntax.kind()) { Some(Module { syntax }) } else { None }
1637 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1641 impl ast::VisibilityOwner for Module {}
1642 impl ast::NameOwner for Module {}
1643 impl ast::AttrsOwner for Module {}
1644 impl ast::DocCommentsOwner for Module {}
1646 pub fn item_list(&self) -> Option<ItemList> {
1647 super::child_opt(self)
1652 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1653 pub struct ModuleItem {
1654 pub(crate) syntax: SyntaxNode,
1657 impl AstNode for ModuleItem {
1658 fn can_cast(kind: SyntaxKind) -> bool {
1660 | STRUCT_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_BLOCK | USE_ITEM | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE => true,
1664 fn cast(syntax: SyntaxNode) -> Option<Self> {
1665 if Self::can_cast(syntax.kind()) { Some(ModuleItem { syntax }) } else { None }
1667 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1671 #[derive(Debug, Clone, PartialEq, Eq)]
1672 pub enum ModuleItemKind {
1673 StructDef(StructDef),
1677 TypeAliasDef(TypeAliasDef),
1678 ImplBlock(ImplBlock),
1680 ExternCrateItem(ExternCrateItem),
1682 StaticDef(StaticDef),
1685 impl From<StructDef> for ModuleItem {
1686 fn from(n: StructDef) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1688 impl From<EnumDef> for ModuleItem {
1689 fn from(n: EnumDef) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1691 impl From<FnDef> for ModuleItem {
1692 fn from(n: FnDef) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1694 impl From<TraitDef> for ModuleItem {
1695 fn from(n: TraitDef) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1697 impl From<TypeAliasDef> for ModuleItem {
1698 fn from(n: TypeAliasDef) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1700 impl From<ImplBlock> for ModuleItem {
1701 fn from(n: ImplBlock) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1703 impl From<UseItem> for ModuleItem {
1704 fn from(n: UseItem) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1706 impl From<ExternCrateItem> for ModuleItem {
1707 fn from(n: ExternCrateItem) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1709 impl From<ConstDef> for ModuleItem {
1710 fn from(n: ConstDef) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1712 impl From<StaticDef> for ModuleItem {
1713 fn from(n: StaticDef) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1715 impl From<Module> for ModuleItem {
1716 fn from(n: Module) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1719 pub fn kind(&self) -> ModuleItemKind {
1720 match self.syntax.kind() {
1721 STRUCT_DEF => ModuleItemKind::StructDef(StructDef::cast(self.syntax.clone()).unwrap()),
1722 ENUM_DEF => ModuleItemKind::EnumDef(EnumDef::cast(self.syntax.clone()).unwrap()),
1723 FN_DEF => ModuleItemKind::FnDef(FnDef::cast(self.syntax.clone()).unwrap()),
1724 TRAIT_DEF => ModuleItemKind::TraitDef(TraitDef::cast(self.syntax.clone()).unwrap()),
1725 TYPE_ALIAS_DEF => ModuleItemKind::TypeAliasDef(TypeAliasDef::cast(self.syntax.clone()).unwrap()),
1726 IMPL_BLOCK => ModuleItemKind::ImplBlock(ImplBlock::cast(self.syntax.clone()).unwrap()),
1727 USE_ITEM => ModuleItemKind::UseItem(UseItem::cast(self.syntax.clone()).unwrap()),
1728 EXTERN_CRATE_ITEM => ModuleItemKind::ExternCrateItem(ExternCrateItem::cast(self.syntax.clone()).unwrap()),
1729 CONST_DEF => ModuleItemKind::ConstDef(ConstDef::cast(self.syntax.clone()).unwrap()),
1730 STATIC_DEF => ModuleItemKind::StaticDef(StaticDef::cast(self.syntax.clone()).unwrap()),
1731 MODULE => ModuleItemKind::Module(Module::cast(self.syntax.clone()).unwrap()),
1732 _ => unreachable!(),
1740 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1742 pub(crate) syntax: SyntaxNode,
1745 impl AstNode for Name {
1746 fn can_cast(kind: SyntaxKind) -> bool {
1752 fn cast(syntax: SyntaxNode) -> Option<Self> {
1753 if Self::can_cast(syntax.kind()) { Some(Name { syntax }) } else { None }
1755 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1762 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1763 pub struct NameRef {
1764 pub(crate) syntax: SyntaxNode,
1767 impl AstNode for NameRef {
1768 fn can_cast(kind: SyntaxKind) -> bool {
1774 fn cast(syntax: SyntaxNode) -> Option<Self> {
1775 if Self::can_cast(syntax.kind()) { Some(NameRef { syntax }) } else { None }
1777 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1784 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1785 pub struct NamedField {
1786 pub(crate) syntax: SyntaxNode,
1789 impl AstNode for NamedField {
1790 fn can_cast(kind: SyntaxKind) -> bool {
1792 NAMED_FIELD => true,
1796 fn cast(syntax: SyntaxNode) -> Option<Self> {
1797 if Self::can_cast(syntax.kind()) { Some(NamedField { syntax }) } else { None }
1799 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1804 pub fn name_ref(&self) -> Option<NameRef> {
1805 super::child_opt(self)
1808 pub fn expr(&self) -> Option<Expr> {
1809 super::child_opt(self)
1814 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1815 pub struct NamedFieldDef {
1816 pub(crate) syntax: SyntaxNode,
1819 impl AstNode for NamedFieldDef {
1820 fn can_cast(kind: SyntaxKind) -> bool {
1822 NAMED_FIELD_DEF => true,
1826 fn cast(syntax: SyntaxNode) -> Option<Self> {
1827 if Self::can_cast(syntax.kind()) { Some(NamedFieldDef { syntax }) } else { None }
1829 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1833 impl ast::VisibilityOwner for NamedFieldDef {}
1834 impl ast::NameOwner for NamedFieldDef {}
1835 impl ast::AttrsOwner for NamedFieldDef {}
1836 impl ast::DocCommentsOwner for NamedFieldDef {}
1837 impl ast::TypeAscriptionOwner for NamedFieldDef {}
1838 impl NamedFieldDef {}
1840 // NamedFieldDefList
1841 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1842 pub struct NamedFieldDefList {
1843 pub(crate) syntax: SyntaxNode,
1846 impl AstNode for NamedFieldDefList {
1847 fn can_cast(kind: SyntaxKind) -> bool {
1849 NAMED_FIELD_DEF_LIST => true,
1853 fn cast(syntax: SyntaxNode) -> Option<Self> {
1854 if Self::can_cast(syntax.kind()) { Some(NamedFieldDefList { syntax }) } else { None }
1856 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1860 impl NamedFieldDefList {
1861 pub fn fields(&self) -> impl Iterator<Item = NamedFieldDef> {
1862 super::children(self)
1867 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1868 pub struct NamedFieldList {
1869 pub(crate) syntax: SyntaxNode,
1872 impl AstNode for NamedFieldList {
1873 fn can_cast(kind: SyntaxKind) -> bool {
1875 NAMED_FIELD_LIST => true,
1879 fn cast(syntax: SyntaxNode) -> Option<Self> {
1880 if Self::can_cast(syntax.kind()) { Some(NamedFieldList { syntax }) } else { None }
1882 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1886 impl NamedFieldList {
1887 pub fn fields(&self) -> impl Iterator<Item = NamedField> {
1888 super::children(self)
1891 pub fn spread(&self) -> Option<Expr> {
1892 super::child_opt(self)
1897 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1898 pub struct NeverType {
1899 pub(crate) syntax: SyntaxNode,
1902 impl AstNode for NeverType {
1903 fn can_cast(kind: SyntaxKind) -> bool {
1909 fn cast(syntax: SyntaxNode) -> Option<Self> {
1910 if Self::can_cast(syntax.kind()) { Some(NeverType { syntax }) } else { None }
1912 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1919 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1920 pub struct NominalDef {
1921 pub(crate) syntax: SyntaxNode,
1924 impl AstNode for NominalDef {
1925 fn can_cast(kind: SyntaxKind) -> bool {
1927 | STRUCT_DEF | ENUM_DEF => true,
1931 fn cast(syntax: SyntaxNode) -> Option<Self> {
1932 if Self::can_cast(syntax.kind()) { Some(NominalDef { syntax }) } else { None }
1934 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1938 #[derive(Debug, Clone, PartialEq, Eq)]
1939 pub enum NominalDefKind {
1940 StructDef(StructDef),
1943 impl From<StructDef> for NominalDef {
1944 fn from(n: StructDef) -> NominalDef { NominalDef { syntax: n.syntax } }
1946 impl From<EnumDef> for NominalDef {
1947 fn from(n: EnumDef) -> NominalDef { NominalDef { syntax: n.syntax } }
1950 pub fn kind(&self) -> NominalDefKind {
1951 match self.syntax.kind() {
1952 STRUCT_DEF => NominalDefKind::StructDef(StructDef::cast(self.syntax.clone()).unwrap()),
1953 ENUM_DEF => NominalDefKind::EnumDef(EnumDef::cast(self.syntax.clone()).unwrap()),
1954 _ => unreachable!(),
1959 impl ast::NameOwner for NominalDef {}
1960 impl ast::TypeParamsOwner for NominalDef {}
1961 impl ast::AttrsOwner for NominalDef {}
1965 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1967 pub(crate) syntax: SyntaxNode,
1970 impl AstNode for Param {
1971 fn can_cast(kind: SyntaxKind) -> bool {
1977 fn cast(syntax: SyntaxNode) -> Option<Self> {
1978 if Self::can_cast(syntax.kind()) { Some(Param { syntax }) } else { None }
1980 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1984 impl ast::TypeAscriptionOwner for Param {}
1986 pub fn pat(&self) -> Option<Pat> {
1987 super::child_opt(self)
1992 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1993 pub struct ParamList {
1994 pub(crate) syntax: SyntaxNode,
1997 impl AstNode for ParamList {
1998 fn can_cast(kind: SyntaxKind) -> bool {
2004 fn cast(syntax: SyntaxNode) -> Option<Self> {
2005 if Self::can_cast(syntax.kind()) { Some(ParamList { syntax }) } else { None }
2007 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2012 pub fn params(&self) -> impl Iterator<Item = Param> {
2013 super::children(self)
2016 pub fn self_param(&self) -> Option<SelfParam> {
2017 super::child_opt(self)
2022 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2023 pub struct ParenExpr {
2024 pub(crate) syntax: SyntaxNode,
2027 impl AstNode for ParenExpr {
2028 fn can_cast(kind: SyntaxKind) -> bool {
2034 fn cast(syntax: SyntaxNode) -> Option<Self> {
2035 if Self::can_cast(syntax.kind()) { Some(ParenExpr { syntax }) } else { None }
2037 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2042 pub fn expr(&self) -> Option<Expr> {
2043 super::child_opt(self)
2048 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2049 pub struct ParenType {
2050 pub(crate) syntax: SyntaxNode,
2053 impl AstNode for ParenType {
2054 fn can_cast(kind: SyntaxKind) -> bool {
2060 fn cast(syntax: SyntaxNode) -> Option<Self> {
2061 if Self::can_cast(syntax.kind()) { Some(ParenType { syntax }) } else { None }
2063 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2068 pub fn type_ref(&self) -> Option<TypeRef> {
2069 super::child_opt(self)
2074 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2076 pub(crate) syntax: SyntaxNode,
2079 impl AstNode for Pat {
2080 fn can_cast(kind: SyntaxKind) -> bool {
2082 | REF_PAT | BIND_PAT | PLACEHOLDER_PAT | PATH_PAT | STRUCT_PAT | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => true,
2086 fn cast(syntax: SyntaxNode) -> Option<Self> {
2087 if Self::can_cast(syntax.kind()) { Some(Pat { syntax }) } else { None }
2089 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2093 #[derive(Debug, Clone, PartialEq, Eq)]
2097 PlaceholderPat(PlaceholderPat),
2099 StructPat(StructPat),
2100 TupleStructPat(TupleStructPat),
2104 LiteralPat(LiteralPat),
2106 impl From<RefPat> for Pat {
2107 fn from(n: RefPat) -> Pat { Pat { syntax: n.syntax } }
2109 impl From<BindPat> for Pat {
2110 fn from(n: BindPat) -> Pat { Pat { syntax: n.syntax } }
2112 impl From<PlaceholderPat> for Pat {
2113 fn from(n: PlaceholderPat) -> Pat { Pat { syntax: n.syntax } }
2115 impl From<PathPat> for Pat {
2116 fn from(n: PathPat) -> Pat { Pat { syntax: n.syntax } }
2118 impl From<StructPat> for Pat {
2119 fn from(n: StructPat) -> Pat { Pat { syntax: n.syntax } }
2121 impl From<TupleStructPat> for Pat {
2122 fn from(n: TupleStructPat) -> Pat { Pat { syntax: n.syntax } }
2124 impl From<TuplePat> for Pat {
2125 fn from(n: TuplePat) -> Pat { Pat { syntax: n.syntax } }
2127 impl From<SlicePat> for Pat {
2128 fn from(n: SlicePat) -> Pat { Pat { syntax: n.syntax } }
2130 impl From<RangePat> for Pat {
2131 fn from(n: RangePat) -> Pat { Pat { syntax: n.syntax } }
2133 impl From<LiteralPat> for Pat {
2134 fn from(n: LiteralPat) -> Pat { Pat { syntax: n.syntax } }
2137 pub fn kind(&self) -> PatKind {
2138 match self.syntax.kind() {
2139 REF_PAT => PatKind::RefPat(RefPat::cast(self.syntax.clone()).unwrap()),
2140 BIND_PAT => PatKind::BindPat(BindPat::cast(self.syntax.clone()).unwrap()),
2141 PLACEHOLDER_PAT => PatKind::PlaceholderPat(PlaceholderPat::cast(self.syntax.clone()).unwrap()),
2142 PATH_PAT => PatKind::PathPat(PathPat::cast(self.syntax.clone()).unwrap()),
2143 STRUCT_PAT => PatKind::StructPat(StructPat::cast(self.syntax.clone()).unwrap()),
2144 TUPLE_STRUCT_PAT => PatKind::TupleStructPat(TupleStructPat::cast(self.syntax.clone()).unwrap()),
2145 TUPLE_PAT => PatKind::TuplePat(TuplePat::cast(self.syntax.clone()).unwrap()),
2146 SLICE_PAT => PatKind::SlicePat(SlicePat::cast(self.syntax.clone()).unwrap()),
2147 RANGE_PAT => PatKind::RangePat(RangePat::cast(self.syntax.clone()).unwrap()),
2148 LITERAL_PAT => PatKind::LiteralPat(LiteralPat::cast(self.syntax.clone()).unwrap()),
2149 _ => unreachable!(),
2157 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2159 pub(crate) syntax: SyntaxNode,
2162 impl AstNode for Path {
2163 fn can_cast(kind: SyntaxKind) -> bool {
2169 fn cast(syntax: SyntaxNode) -> Option<Self> {
2170 if Self::can_cast(syntax.kind()) { Some(Path { syntax }) } else { None }
2172 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2177 pub fn segment(&self) -> Option<PathSegment> {
2178 super::child_opt(self)
2181 pub fn qualifier(&self) -> Option<Path> {
2182 super::child_opt(self)
2187 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2188 pub struct PathExpr {
2189 pub(crate) syntax: SyntaxNode,
2192 impl AstNode for PathExpr {
2193 fn can_cast(kind: SyntaxKind) -> bool {
2199 fn cast(syntax: SyntaxNode) -> Option<Self> {
2200 if Self::can_cast(syntax.kind()) { Some(PathExpr { syntax }) } else { None }
2202 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2207 pub fn path(&self) -> Option<Path> {
2208 super::child_opt(self)
2213 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2214 pub struct PathPat {
2215 pub(crate) syntax: SyntaxNode,
2218 impl AstNode for PathPat {
2219 fn can_cast(kind: SyntaxKind) -> bool {
2225 fn cast(syntax: SyntaxNode) -> Option<Self> {
2226 if Self::can_cast(syntax.kind()) { Some(PathPat { syntax }) } else { None }
2228 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2233 pub fn path(&self) -> Option<Path> {
2234 super::child_opt(self)
2239 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2240 pub struct PathSegment {
2241 pub(crate) syntax: SyntaxNode,
2244 impl AstNode for PathSegment {
2245 fn can_cast(kind: SyntaxKind) -> bool {
2247 PATH_SEGMENT => true,
2251 fn cast(syntax: SyntaxNode) -> Option<Self> {
2252 if Self::can_cast(syntax.kind()) { Some(PathSegment { syntax }) } else { None }
2254 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2259 pub fn name_ref(&self) -> Option<NameRef> {
2260 super::child_opt(self)
2263 pub fn type_arg_list(&self) -> Option<TypeArgList> {
2264 super::child_opt(self)
2269 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2270 pub struct PathType {
2271 pub(crate) syntax: SyntaxNode,
2274 impl AstNode for PathType {
2275 fn can_cast(kind: SyntaxKind) -> bool {
2281 fn cast(syntax: SyntaxNode) -> Option<Self> {
2282 if Self::can_cast(syntax.kind()) { Some(PathType { syntax }) } else { None }
2284 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2289 pub fn path(&self) -> Option<Path> {
2290 super::child_opt(self)
2295 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2296 pub struct PlaceholderPat {
2297 pub(crate) syntax: SyntaxNode,
2300 impl AstNode for PlaceholderPat {
2301 fn can_cast(kind: SyntaxKind) -> bool {
2303 PLACEHOLDER_PAT => true,
2307 fn cast(syntax: SyntaxNode) -> Option<Self> {
2308 if Self::can_cast(syntax.kind()) { Some(PlaceholderPat { syntax }) } else { None }
2310 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2314 impl PlaceholderPat {}
2317 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2318 pub struct PlaceholderType {
2319 pub(crate) syntax: SyntaxNode,
2322 impl AstNode for PlaceholderType {
2323 fn can_cast(kind: SyntaxKind) -> bool {
2325 PLACEHOLDER_TYPE => true,
2329 fn cast(syntax: SyntaxNode) -> Option<Self> {
2330 if Self::can_cast(syntax.kind()) { Some(PlaceholderType { syntax }) } else { None }
2332 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2336 impl PlaceholderType {}
2339 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2340 pub struct PointerType {
2341 pub(crate) syntax: SyntaxNode,
2344 impl AstNode for PointerType {
2345 fn can_cast(kind: SyntaxKind) -> bool {
2347 POINTER_TYPE => true,
2351 fn cast(syntax: SyntaxNode) -> Option<Self> {
2352 if Self::can_cast(syntax.kind()) { Some(PointerType { syntax }) } else { None }
2354 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2359 pub fn type_ref(&self) -> Option<TypeRef> {
2360 super::child_opt(self)
2365 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2366 pub struct PosFieldDef {
2367 pub(crate) syntax: SyntaxNode,
2370 impl AstNode for PosFieldDef {
2371 fn can_cast(kind: SyntaxKind) -> bool {
2373 POS_FIELD_DEF => true,
2377 fn cast(syntax: SyntaxNode) -> Option<Self> {
2378 if Self::can_cast(syntax.kind()) { Some(PosFieldDef { syntax }) } else { None }
2380 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2384 impl ast::VisibilityOwner for PosFieldDef {}
2385 impl ast::AttrsOwner for PosFieldDef {}
2387 pub fn type_ref(&self) -> Option<TypeRef> {
2388 super::child_opt(self)
2393 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2394 pub struct PosFieldDefList {
2395 pub(crate) syntax: SyntaxNode,
2398 impl AstNode for PosFieldDefList {
2399 fn can_cast(kind: SyntaxKind) -> bool {
2401 POS_FIELD_DEF_LIST => true,
2405 fn cast(syntax: SyntaxNode) -> Option<Self> {
2406 if Self::can_cast(syntax.kind()) { Some(PosFieldDefList { syntax }) } else { None }
2408 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2412 impl PosFieldDefList {
2413 pub fn fields(&self) -> impl Iterator<Item = PosFieldDef> {
2414 super::children(self)
2419 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2420 pub struct PrefixExpr {
2421 pub(crate) syntax: SyntaxNode,
2424 impl AstNode for PrefixExpr {
2425 fn can_cast(kind: SyntaxKind) -> bool {
2427 PREFIX_EXPR => true,
2431 fn cast(syntax: SyntaxNode) -> Option<Self> {
2432 if Self::can_cast(syntax.kind()) { Some(PrefixExpr { syntax }) } else { None }
2434 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2439 pub fn expr(&self) -> Option<Expr> {
2440 super::child_opt(self)
2445 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2446 pub struct RangeExpr {
2447 pub(crate) syntax: SyntaxNode,
2450 impl AstNode for RangeExpr {
2451 fn can_cast(kind: SyntaxKind) -> bool {
2457 fn cast(syntax: SyntaxNode) -> Option<Self> {
2458 if Self::can_cast(syntax.kind()) { Some(RangeExpr { syntax }) } else { None }
2460 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2467 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2468 pub struct RangePat {
2469 pub(crate) syntax: SyntaxNode,
2472 impl AstNode for RangePat {
2473 fn can_cast(kind: SyntaxKind) -> bool {
2479 fn cast(syntax: SyntaxNode) -> Option<Self> {
2480 if Self::can_cast(syntax.kind()) { Some(RangePat { syntax }) } else { None }
2482 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2489 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2490 pub struct RefExpr {
2491 pub(crate) syntax: SyntaxNode,
2494 impl AstNode for RefExpr {
2495 fn can_cast(kind: SyntaxKind) -> bool {
2501 fn cast(syntax: SyntaxNode) -> Option<Self> {
2502 if Self::can_cast(syntax.kind()) { Some(RefExpr { syntax }) } else { None }
2504 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2509 pub fn expr(&self) -> Option<Expr> {
2510 super::child_opt(self)
2515 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2517 pub(crate) syntax: SyntaxNode,
2520 impl AstNode for RefPat {
2521 fn can_cast(kind: SyntaxKind) -> bool {
2527 fn cast(syntax: SyntaxNode) -> Option<Self> {
2528 if Self::can_cast(syntax.kind()) { Some(RefPat { syntax }) } else { None }
2530 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2535 pub fn pat(&self) -> Option<Pat> {
2536 super::child_opt(self)
2541 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2542 pub struct ReferenceType {
2543 pub(crate) syntax: SyntaxNode,
2546 impl AstNode for ReferenceType {
2547 fn can_cast(kind: SyntaxKind) -> bool {
2549 REFERENCE_TYPE => true,
2553 fn cast(syntax: SyntaxNode) -> Option<Self> {
2554 if Self::can_cast(syntax.kind()) { Some(ReferenceType { syntax }) } else { None }
2556 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2560 impl ReferenceType {
2561 pub fn type_ref(&self) -> Option<TypeRef> {
2562 super::child_opt(self)
2567 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2568 pub struct RetType {
2569 pub(crate) syntax: SyntaxNode,
2572 impl AstNode for RetType {
2573 fn can_cast(kind: SyntaxKind) -> bool {
2579 fn cast(syntax: SyntaxNode) -> Option<Self> {
2580 if Self::can_cast(syntax.kind()) { Some(RetType { syntax }) } else { None }
2582 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2587 pub fn type_ref(&self) -> Option<TypeRef> {
2588 super::child_opt(self)
2593 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2594 pub struct ReturnExpr {
2595 pub(crate) syntax: SyntaxNode,
2598 impl AstNode for ReturnExpr {
2599 fn can_cast(kind: SyntaxKind) -> bool {
2601 RETURN_EXPR => true,
2605 fn cast(syntax: SyntaxNode) -> Option<Self> {
2606 if Self::can_cast(syntax.kind()) { Some(ReturnExpr { syntax }) } else { None }
2608 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2613 pub fn expr(&self) -> Option<Expr> {
2614 super::child_opt(self)
2619 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2620 pub struct SelfParam {
2621 pub(crate) syntax: SyntaxNode,
2624 impl AstNode for SelfParam {
2625 fn can_cast(kind: SyntaxKind) -> bool {
2631 fn cast(syntax: SyntaxNode) -> Option<Self> {
2632 if Self::can_cast(syntax.kind()) { Some(SelfParam { syntax }) } else { None }
2634 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2638 impl ast::TypeAscriptionOwner for SelfParam {}
2642 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2643 pub struct SlicePat {
2644 pub(crate) syntax: SyntaxNode,
2647 impl AstNode for SlicePat {
2648 fn can_cast(kind: SyntaxKind) -> bool {
2654 fn cast(syntax: SyntaxNode) -> Option<Self> {
2655 if Self::can_cast(syntax.kind()) { Some(SlicePat { syntax }) } else { None }
2657 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2664 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2665 pub struct SliceType {
2666 pub(crate) syntax: SyntaxNode,
2669 impl AstNode for SliceType {
2670 fn can_cast(kind: SyntaxKind) -> bool {
2676 fn cast(syntax: SyntaxNode) -> Option<Self> {
2677 if Self::can_cast(syntax.kind()) { Some(SliceType { syntax }) } else { None }
2679 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2684 pub fn type_ref(&self) -> Option<TypeRef> {
2685 super::child_opt(self)
2690 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2691 pub struct SourceFile {
2692 pub(crate) syntax: SyntaxNode,
2695 impl AstNode for SourceFile {
2696 fn can_cast(kind: SyntaxKind) -> bool {
2698 SOURCE_FILE => true,
2702 fn cast(syntax: SyntaxNode) -> Option<Self> {
2703 if Self::can_cast(syntax.kind()) { Some(SourceFile { syntax }) } else { None }
2705 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2709 impl ast::ModuleItemOwner for SourceFile {}
2710 impl ast::FnDefOwner for SourceFile {}
2712 pub fn modules(&self) -> impl Iterator<Item = Module> {
2713 super::children(self)
2718 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2719 pub struct StaticDef {
2720 pub(crate) syntax: SyntaxNode,
2723 impl AstNode for StaticDef {
2724 fn can_cast(kind: SyntaxKind) -> bool {
2730 fn cast(syntax: SyntaxNode) -> Option<Self> {
2731 if Self::can_cast(syntax.kind()) { Some(StaticDef { syntax }) } else { None }
2733 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2737 impl ast::VisibilityOwner for StaticDef {}
2738 impl ast::NameOwner for StaticDef {}
2739 impl ast::TypeParamsOwner for StaticDef {}
2740 impl ast::AttrsOwner for StaticDef {}
2741 impl ast::DocCommentsOwner for StaticDef {}
2742 impl ast::TypeAscriptionOwner for StaticDef {}
2744 pub fn body(&self) -> Option<Expr> {
2745 super::child_opt(self)
2750 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2752 pub(crate) syntax: SyntaxNode,
2755 impl AstNode for Stmt {
2756 fn can_cast(kind: SyntaxKind) -> bool {
2758 | EXPR_STMT | LET_STMT => true,
2762 fn cast(syntax: SyntaxNode) -> Option<Self> {
2763 if Self::can_cast(syntax.kind()) { Some(Stmt { syntax }) } else { None }
2765 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2769 #[derive(Debug, Clone, PartialEq, Eq)]
2774 impl From<ExprStmt> for Stmt {
2775 fn from(n: ExprStmt) -> Stmt { Stmt { syntax: n.syntax } }
2777 impl From<LetStmt> for Stmt {
2778 fn from(n: LetStmt) -> Stmt { Stmt { syntax: n.syntax } }
2781 pub fn kind(&self) -> StmtKind {
2782 match self.syntax.kind() {
2783 EXPR_STMT => StmtKind::ExprStmt(ExprStmt::cast(self.syntax.clone()).unwrap()),
2784 LET_STMT => StmtKind::LetStmt(LetStmt::cast(self.syntax.clone()).unwrap()),
2785 _ => unreachable!(),
2793 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2794 pub struct StructDef {
2795 pub(crate) syntax: SyntaxNode,
2798 impl AstNode for StructDef {
2799 fn can_cast(kind: SyntaxKind) -> bool {
2805 fn cast(syntax: SyntaxNode) -> Option<Self> {
2806 if Self::can_cast(syntax.kind()) { Some(StructDef { syntax }) } else { None }
2808 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2812 impl ast::VisibilityOwner for StructDef {}
2813 impl ast::NameOwner for StructDef {}
2814 impl ast::TypeParamsOwner for StructDef {}
2815 impl ast::AttrsOwner for StructDef {}
2816 impl ast::DocCommentsOwner for StructDef {}
2820 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2821 pub struct StructLit {
2822 pub(crate) syntax: SyntaxNode,
2825 impl AstNode for StructLit {
2826 fn can_cast(kind: SyntaxKind) -> bool {
2832 fn cast(syntax: SyntaxNode) -> Option<Self> {
2833 if Self::can_cast(syntax.kind()) { Some(StructLit { syntax }) } else { None }
2835 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2840 pub fn path(&self) -> Option<Path> {
2841 super::child_opt(self)
2844 pub fn named_field_list(&self) -> Option<NamedFieldList> {
2845 super::child_opt(self)
2850 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2851 pub struct StructPat {
2852 pub(crate) syntax: SyntaxNode,
2855 impl AstNode for StructPat {
2856 fn can_cast(kind: SyntaxKind) -> bool {
2862 fn cast(syntax: SyntaxNode) -> Option<Self> {
2863 if Self::can_cast(syntax.kind()) { Some(StructPat { syntax }) } else { None }
2865 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2870 pub fn field_pat_list(&self) -> Option<FieldPatList> {
2871 super::child_opt(self)
2874 pub fn path(&self) -> Option<Path> {
2875 super::child_opt(self)
2880 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2881 pub struct TokenTree {
2882 pub(crate) syntax: SyntaxNode,
2885 impl AstNode for TokenTree {
2886 fn can_cast(kind: SyntaxKind) -> bool {
2892 fn cast(syntax: SyntaxNode) -> Option<Self> {
2893 if Self::can_cast(syntax.kind()) { Some(TokenTree { syntax }) } else { None }
2895 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2902 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2903 pub struct TraitDef {
2904 pub(crate) syntax: SyntaxNode,
2907 impl AstNode for TraitDef {
2908 fn can_cast(kind: SyntaxKind) -> bool {
2914 fn cast(syntax: SyntaxNode) -> Option<Self> {
2915 if Self::can_cast(syntax.kind()) { Some(TraitDef { syntax }) } else { None }
2917 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2921 impl ast::VisibilityOwner for TraitDef {}
2922 impl ast::NameOwner for TraitDef {}
2923 impl ast::AttrsOwner for TraitDef {}
2924 impl ast::DocCommentsOwner for TraitDef {}
2925 impl ast::TypeParamsOwner for TraitDef {}
2926 impl ast::TypeBoundsOwner for TraitDef {}
2928 pub fn item_list(&self) -> Option<ItemList> {
2929 super::child_opt(self)
2934 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2935 pub struct TryBlockExpr {
2936 pub(crate) syntax: SyntaxNode,
2939 impl AstNode for TryBlockExpr {
2940 fn can_cast(kind: SyntaxKind) -> bool {
2942 TRY_BLOCK_EXPR => true,
2946 fn cast(syntax: SyntaxNode) -> Option<Self> {
2947 if Self::can_cast(syntax.kind()) { Some(TryBlockExpr { syntax }) } else { None }
2949 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2953 impl ast::TryBlockBodyOwner for TryBlockExpr {}
2954 impl TryBlockExpr {}
2957 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2958 pub struct TryExpr {
2959 pub(crate) syntax: SyntaxNode,
2962 impl AstNode for TryExpr {
2963 fn can_cast(kind: SyntaxKind) -> bool {
2969 fn cast(syntax: SyntaxNode) -> Option<Self> {
2970 if Self::can_cast(syntax.kind()) { Some(TryExpr { syntax }) } else { None }
2972 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2977 pub fn expr(&self) -> Option<Expr> {
2978 super::child_opt(self)
2983 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2984 pub struct TupleExpr {
2985 pub(crate) syntax: SyntaxNode,
2988 impl AstNode for TupleExpr {
2989 fn can_cast(kind: SyntaxKind) -> bool {
2995 fn cast(syntax: SyntaxNode) -> Option<Self> {
2996 if Self::can_cast(syntax.kind()) { Some(TupleExpr { syntax }) } else { None }
2998 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3003 pub fn exprs(&self) -> impl Iterator<Item = Expr> {
3004 super::children(self)
3009 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3010 pub struct TuplePat {
3011 pub(crate) syntax: SyntaxNode,
3014 impl AstNode for TuplePat {
3015 fn can_cast(kind: SyntaxKind) -> bool {
3021 fn cast(syntax: SyntaxNode) -> Option<Self> {
3022 if Self::can_cast(syntax.kind()) { Some(TuplePat { syntax }) } else { None }
3024 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3029 pub fn args(&self) -> impl Iterator<Item = Pat> {
3030 super::children(self)
3035 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3036 pub struct TupleStructPat {
3037 pub(crate) syntax: SyntaxNode,
3040 impl AstNode for TupleStructPat {
3041 fn can_cast(kind: SyntaxKind) -> bool {
3043 TUPLE_STRUCT_PAT => true,
3047 fn cast(syntax: SyntaxNode) -> Option<Self> {
3048 if Self::can_cast(syntax.kind()) { Some(TupleStructPat { syntax }) } else { None }
3050 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3054 impl TupleStructPat {
3055 pub fn args(&self) -> impl Iterator<Item = Pat> {
3056 super::children(self)
3059 pub fn path(&self) -> Option<Path> {
3060 super::child_opt(self)
3065 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3066 pub struct TupleType {
3067 pub(crate) syntax: SyntaxNode,
3070 impl AstNode for TupleType {
3071 fn can_cast(kind: SyntaxKind) -> bool {
3077 fn cast(syntax: SyntaxNode) -> Option<Self> {
3078 if Self::can_cast(syntax.kind()) { Some(TupleType { syntax }) } else { None }
3080 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3085 pub fn fields(&self) -> impl Iterator<Item = TypeRef> {
3086 super::children(self)
3091 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3092 pub struct TypeAliasDef {
3093 pub(crate) syntax: SyntaxNode,
3096 impl AstNode for TypeAliasDef {
3097 fn can_cast(kind: SyntaxKind) -> bool {
3099 TYPE_ALIAS_DEF => true,
3103 fn cast(syntax: SyntaxNode) -> Option<Self> {
3104 if Self::can_cast(syntax.kind()) { Some(TypeAliasDef { syntax }) } else { None }
3106 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3110 impl ast::VisibilityOwner for TypeAliasDef {}
3111 impl ast::NameOwner for TypeAliasDef {}
3112 impl ast::TypeParamsOwner for TypeAliasDef {}
3113 impl ast::AttrsOwner for TypeAliasDef {}
3114 impl ast::DocCommentsOwner for TypeAliasDef {}
3115 impl ast::TypeBoundsOwner for TypeAliasDef {}
3117 pub fn type_ref(&self) -> Option<TypeRef> {
3118 super::child_opt(self)
3123 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3124 pub struct TypeArg {
3125 pub(crate) syntax: SyntaxNode,
3128 impl AstNode for TypeArg {
3129 fn can_cast(kind: SyntaxKind) -> bool {
3135 fn cast(syntax: SyntaxNode) -> Option<Self> {
3136 if Self::can_cast(syntax.kind()) { Some(TypeArg { syntax }) } else { None }
3138 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3143 pub fn type_ref(&self) -> Option<TypeRef> {
3144 super::child_opt(self)
3149 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3150 pub struct TypeArgList {
3151 pub(crate) syntax: SyntaxNode,
3154 impl AstNode for TypeArgList {
3155 fn can_cast(kind: SyntaxKind) -> bool {
3157 TYPE_ARG_LIST => true,
3161 fn cast(syntax: SyntaxNode) -> Option<Self> {
3162 if Self::can_cast(syntax.kind()) { Some(TypeArgList { syntax }) } else { None }
3164 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3169 pub fn type_args(&self) -> impl Iterator<Item = TypeArg> {
3170 super::children(self)
3173 pub fn lifetime_args(&self) -> impl Iterator<Item = LifetimeArg> {
3174 super::children(self)
3177 pub fn assoc_type_args(&self) -> impl Iterator<Item = AssocTypeArg> {
3178 super::children(self)
3183 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3184 pub struct TypeBound {
3185 pub(crate) syntax: SyntaxNode,
3188 impl AstNode for TypeBound {
3189 fn can_cast(kind: SyntaxKind) -> bool {
3195 fn cast(syntax: SyntaxNode) -> Option<Self> {
3196 if Self::can_cast(syntax.kind()) { Some(TypeBound { syntax }) } else { None }
3198 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3203 pub fn type_ref(&self) -> Option<TypeRef> {
3204 super::child_opt(self)
3209 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3210 pub struct TypeBoundList {
3211 pub(crate) syntax: SyntaxNode,
3214 impl AstNode for TypeBoundList {
3215 fn can_cast(kind: SyntaxKind) -> bool {
3217 TYPE_BOUND_LIST => true,
3221 fn cast(syntax: SyntaxNode) -> Option<Self> {
3222 if Self::can_cast(syntax.kind()) { Some(TypeBoundList { syntax }) } else { None }
3224 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3228 impl TypeBoundList {
3229 pub fn bounds(&self) -> impl Iterator<Item = TypeBound> {
3230 super::children(self)
3235 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3236 pub struct TypeParam {
3237 pub(crate) syntax: SyntaxNode,
3240 impl AstNode for TypeParam {
3241 fn can_cast(kind: SyntaxKind) -> bool {
3247 fn cast(syntax: SyntaxNode) -> Option<Self> {
3248 if Self::can_cast(syntax.kind()) { Some(TypeParam { syntax }) } else { None }
3250 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3254 impl ast::NameOwner for TypeParam {}
3255 impl ast::AttrsOwner for TypeParam {}
3256 impl ast::TypeBoundsOwner for TypeParam {}
3257 impl ast::DefaultTypeParamOwner for TypeParam {}
3261 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3262 pub struct TypeParamList {
3263 pub(crate) syntax: SyntaxNode,
3266 impl AstNode for TypeParamList {
3267 fn can_cast(kind: SyntaxKind) -> bool {
3269 TYPE_PARAM_LIST => true,
3273 fn cast(syntax: SyntaxNode) -> Option<Self> {
3274 if Self::can_cast(syntax.kind()) { Some(TypeParamList { syntax }) } else { None }
3276 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3280 impl TypeParamList {
3281 pub fn type_params(&self) -> impl Iterator<Item = TypeParam> {
3282 super::children(self)
3285 pub fn lifetime_params(&self) -> impl Iterator<Item = LifetimeParam> {
3286 super::children(self)
3291 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3292 pub struct TypeRef {
3293 pub(crate) syntax: SyntaxNode,
3296 impl AstNode for TypeRef {
3297 fn can_cast(kind: SyntaxKind) -> bool {
3299 | PAREN_TYPE | TUPLE_TYPE | NEVER_TYPE | PATH_TYPE | POINTER_TYPE | ARRAY_TYPE | SLICE_TYPE | REFERENCE_TYPE | PLACEHOLDER_TYPE | FN_POINTER_TYPE | FOR_TYPE | IMPL_TRAIT_TYPE | DYN_TRAIT_TYPE => true,
3303 fn cast(syntax: SyntaxNode) -> Option<Self> {
3304 if Self::can_cast(syntax.kind()) { Some(TypeRef { syntax }) } else { None }
3306 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3310 #[derive(Debug, Clone, PartialEq, Eq)]
3311 pub enum TypeRefKind {
3312 ParenType(ParenType),
3313 TupleType(TupleType),
3314 NeverType(NeverType),
3316 PointerType(PointerType),
3317 ArrayType(ArrayType),
3318 SliceType(SliceType),
3319 ReferenceType(ReferenceType),
3320 PlaceholderType(PlaceholderType),
3321 FnPointerType(FnPointerType),
3323 ImplTraitType(ImplTraitType),
3324 DynTraitType(DynTraitType),
3326 impl From<ParenType> for TypeRef {
3327 fn from(n: ParenType) -> TypeRef { TypeRef { syntax: n.syntax } }
3329 impl From<TupleType> for TypeRef {
3330 fn from(n: TupleType) -> TypeRef { TypeRef { syntax: n.syntax } }
3332 impl From<NeverType> for TypeRef {
3333 fn from(n: NeverType) -> TypeRef { TypeRef { syntax: n.syntax } }
3335 impl From<PathType> for TypeRef {
3336 fn from(n: PathType) -> TypeRef { TypeRef { syntax: n.syntax } }
3338 impl From<PointerType> for TypeRef {
3339 fn from(n: PointerType) -> TypeRef { TypeRef { syntax: n.syntax } }
3341 impl From<ArrayType> for TypeRef {
3342 fn from(n: ArrayType) -> TypeRef { TypeRef { syntax: n.syntax } }
3344 impl From<SliceType> for TypeRef {
3345 fn from(n: SliceType) -> TypeRef { TypeRef { syntax: n.syntax } }
3347 impl From<ReferenceType> for TypeRef {
3348 fn from(n: ReferenceType) -> TypeRef { TypeRef { syntax: n.syntax } }
3350 impl From<PlaceholderType> for TypeRef {
3351 fn from(n: PlaceholderType) -> TypeRef { TypeRef { syntax: n.syntax } }
3353 impl From<FnPointerType> for TypeRef {
3354 fn from(n: FnPointerType) -> TypeRef { TypeRef { syntax: n.syntax } }
3356 impl From<ForType> for TypeRef {
3357 fn from(n: ForType) -> TypeRef { TypeRef { syntax: n.syntax } }
3359 impl From<ImplTraitType> for TypeRef {
3360 fn from(n: ImplTraitType) -> TypeRef { TypeRef { syntax: n.syntax } }
3362 impl From<DynTraitType> for TypeRef {
3363 fn from(n: DynTraitType) -> TypeRef { TypeRef { syntax: n.syntax } }
3366 pub fn kind(&self) -> TypeRefKind {
3367 match self.syntax.kind() {
3368 PAREN_TYPE => TypeRefKind::ParenType(ParenType::cast(self.syntax.clone()).unwrap()),
3369 TUPLE_TYPE => TypeRefKind::TupleType(TupleType::cast(self.syntax.clone()).unwrap()),
3370 NEVER_TYPE => TypeRefKind::NeverType(NeverType::cast(self.syntax.clone()).unwrap()),
3371 PATH_TYPE => TypeRefKind::PathType(PathType::cast(self.syntax.clone()).unwrap()),
3372 POINTER_TYPE => TypeRefKind::PointerType(PointerType::cast(self.syntax.clone()).unwrap()),
3373 ARRAY_TYPE => TypeRefKind::ArrayType(ArrayType::cast(self.syntax.clone()).unwrap()),
3374 SLICE_TYPE => TypeRefKind::SliceType(SliceType::cast(self.syntax.clone()).unwrap()),
3375 REFERENCE_TYPE => TypeRefKind::ReferenceType(ReferenceType::cast(self.syntax.clone()).unwrap()),
3376 PLACEHOLDER_TYPE => TypeRefKind::PlaceholderType(PlaceholderType::cast(self.syntax.clone()).unwrap()),
3377 FN_POINTER_TYPE => TypeRefKind::FnPointerType(FnPointerType::cast(self.syntax.clone()).unwrap()),
3378 FOR_TYPE => TypeRefKind::ForType(ForType::cast(self.syntax.clone()).unwrap()),
3379 IMPL_TRAIT_TYPE => TypeRefKind::ImplTraitType(ImplTraitType::cast(self.syntax.clone()).unwrap()),
3380 DYN_TRAIT_TYPE => TypeRefKind::DynTraitType(DynTraitType::cast(self.syntax.clone()).unwrap()),
3381 _ => unreachable!(),
3389 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3390 pub struct UseItem {
3391 pub(crate) syntax: SyntaxNode,
3394 impl AstNode for UseItem {
3395 fn can_cast(kind: SyntaxKind) -> bool {
3401 fn cast(syntax: SyntaxNode) -> Option<Self> {
3402 if Self::can_cast(syntax.kind()) { Some(UseItem { syntax }) } else { None }
3404 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3408 impl ast::AttrsOwner for UseItem {}
3410 pub fn use_tree(&self) -> Option<UseTree> {
3411 super::child_opt(self)
3416 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3417 pub struct UseTree {
3418 pub(crate) syntax: SyntaxNode,
3421 impl AstNode for UseTree {
3422 fn can_cast(kind: SyntaxKind) -> bool {
3428 fn cast(syntax: SyntaxNode) -> Option<Self> {
3429 if Self::can_cast(syntax.kind()) { Some(UseTree { syntax }) } else { None }
3431 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3436 pub fn path(&self) -> Option<Path> {
3437 super::child_opt(self)
3440 pub fn use_tree_list(&self) -> Option<UseTreeList> {
3441 super::child_opt(self)
3444 pub fn alias(&self) -> Option<Alias> {
3445 super::child_opt(self)
3450 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3451 pub struct UseTreeList {
3452 pub(crate) syntax: SyntaxNode,
3455 impl AstNode for UseTreeList {
3456 fn can_cast(kind: SyntaxKind) -> bool {
3458 USE_TREE_LIST => true,
3462 fn cast(syntax: SyntaxNode) -> Option<Self> {
3463 if Self::can_cast(syntax.kind()) { Some(UseTreeList { syntax }) } else { None }
3465 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3470 pub fn use_trees(&self) -> impl Iterator<Item = UseTree> {
3471 super::children(self)
3476 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3477 pub struct Visibility {
3478 pub(crate) syntax: SyntaxNode,
3481 impl AstNode for Visibility {
3482 fn can_cast(kind: SyntaxKind) -> bool {
3488 fn cast(syntax: SyntaxNode) -> Option<Self> {
3489 if Self::can_cast(syntax.kind()) { Some(Visibility { syntax }) } else { None }
3491 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3498 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3499 pub struct WhereClause {
3500 pub(crate) syntax: SyntaxNode,
3503 impl AstNode for WhereClause {
3504 fn can_cast(kind: SyntaxKind) -> bool {
3506 WHERE_CLAUSE => true,
3510 fn cast(syntax: SyntaxNode) -> Option<Self> {
3511 if Self::can_cast(syntax.kind()) { Some(WhereClause { syntax }) } else { None }
3513 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3518 pub fn predicates(&self) -> impl Iterator<Item = WherePred> {
3519 super::children(self)
3524 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3525 pub struct WherePred {
3526 pub(crate) syntax: SyntaxNode,
3529 impl AstNode for WherePred {
3530 fn can_cast(kind: SyntaxKind) -> bool {
3536 fn cast(syntax: SyntaxNode) -> Option<Self> {
3537 if Self::can_cast(syntax.kind()) { Some(WherePred { syntax }) } else { None }
3539 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3543 impl ast::TypeBoundsOwner for WherePred {}
3545 pub fn type_ref(&self) -> Option<TypeRef> {
3546 super::child_opt(self)
3551 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3552 pub struct WhileExpr {
3553 pub(crate) syntax: SyntaxNode,
3556 impl AstNode for WhileExpr {
3557 fn can_cast(kind: SyntaxKind) -> bool {
3563 fn cast(syntax: SyntaxNode) -> Option<Self> {
3564 if Self::can_cast(syntax.kind()) { Some(WhileExpr { syntax }) } else { None }
3566 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3570 impl ast::LoopBodyOwner for WhileExpr {}
3572 pub fn condition(&self) -> Option<Condition> {
3573 super::child_opt(self)