1 // Generated file, do not edit by hand, see `crate/ra_tools/src/codegen`
4 ast::{self, AstChildren, AstNode},
8 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
10 pub(crate) syntax: SyntaxNode,
12 impl AstNode for Alias {
13 fn can_cast(kind: SyntaxKind) -> bool {
19 fn cast(syntax: SyntaxNode) -> Option<Self> {
20 if Self::can_cast(syntax.kind()) {
26 fn syntax(&self) -> &SyntaxNode {
30 impl ast::NameOwner for Alias {}
32 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
34 pub(crate) syntax: SyntaxNode,
36 impl AstNode for ArgList {
37 fn can_cast(kind: SyntaxKind) -> bool {
43 fn cast(syntax: SyntaxNode) -> Option<Self> {
44 if Self::can_cast(syntax.kind()) {
50 fn syntax(&self) -> &SyntaxNode {
55 pub fn args(&self) -> AstChildren<Expr> {
56 AstChildren::new(&self.syntax)
59 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
60 pub struct ArrayExpr {
61 pub(crate) syntax: SyntaxNode,
63 impl AstNode for ArrayExpr {
64 fn can_cast(kind: SyntaxKind) -> bool {
70 fn cast(syntax: SyntaxNode) -> Option<Self> {
71 if Self::can_cast(syntax.kind()) {
77 fn syntax(&self) -> &SyntaxNode {
82 pub fn exprs(&self) -> AstChildren<Expr> {
83 AstChildren::new(&self.syntax)
86 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
87 pub struct ArrayType {
88 pub(crate) syntax: SyntaxNode,
90 impl AstNode for ArrayType {
91 fn can_cast(kind: SyntaxKind) -> bool {
97 fn cast(syntax: SyntaxNode) -> Option<Self> {
98 if Self::can_cast(syntax.kind()) {
104 fn syntax(&self) -> &SyntaxNode {
109 pub fn type_ref(&self) -> Option<TypeRef> {
110 AstChildren::new(&self.syntax).next()
112 pub fn expr(&self) -> Option<Expr> {
113 AstChildren::new(&self.syntax).next()
116 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
117 pub struct AssocTypeArg {
118 pub(crate) syntax: SyntaxNode,
120 impl AstNode for AssocTypeArg {
121 fn can_cast(kind: SyntaxKind) -> bool {
123 ASSOC_TYPE_ARG => true,
127 fn cast(syntax: SyntaxNode) -> Option<Self> {
128 if Self::can_cast(syntax.kind()) {
129 Some(Self { syntax })
134 fn syntax(&self) -> &SyntaxNode {
139 pub fn name_ref(&self) -> Option<NameRef> {
140 AstChildren::new(&self.syntax).next()
142 pub fn type_ref(&self) -> Option<TypeRef> {
143 AstChildren::new(&self.syntax).next()
146 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
148 pub(crate) syntax: SyntaxNode,
150 impl AstNode for Attr {
151 fn can_cast(kind: SyntaxKind) -> bool {
157 fn cast(syntax: SyntaxNode) -> Option<Self> {
158 if Self::can_cast(syntax.kind()) {
159 Some(Self { syntax })
164 fn syntax(&self) -> &SyntaxNode {
169 pub fn value(&self) -> Option<TokenTree> {
170 AstChildren::new(&self.syntax).next()
173 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
174 pub struct AwaitExpr {
175 pub(crate) syntax: SyntaxNode,
177 impl AstNode for AwaitExpr {
178 fn can_cast(kind: SyntaxKind) -> bool {
184 fn cast(syntax: SyntaxNode) -> Option<Self> {
185 if Self::can_cast(syntax.kind()) {
186 Some(Self { syntax })
191 fn syntax(&self) -> &SyntaxNode {
196 pub fn expr(&self) -> Option<Expr> {
197 AstChildren::new(&self.syntax).next()
200 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
202 pub(crate) syntax: SyntaxNode,
204 impl AstNode for BinExpr {
205 fn can_cast(kind: SyntaxKind) -> bool {
211 fn cast(syntax: SyntaxNode) -> Option<Self> {
212 if Self::can_cast(syntax.kind()) {
213 Some(Self { syntax })
218 fn syntax(&self) -> &SyntaxNode {
223 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
225 pub(crate) syntax: SyntaxNode,
227 impl AstNode for BindPat {
228 fn can_cast(kind: SyntaxKind) -> bool {
234 fn cast(syntax: SyntaxNode) -> Option<Self> {
235 if Self::can_cast(syntax.kind()) {
236 Some(Self { syntax })
241 fn syntax(&self) -> &SyntaxNode {
245 impl ast::NameOwner for BindPat {}
247 pub fn pat(&self) -> Option<Pat> {
248 AstChildren::new(&self.syntax).next()
251 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
253 pub(crate) syntax: SyntaxNode,
255 impl AstNode for Block {
256 fn can_cast(kind: SyntaxKind) -> bool {
262 fn cast(syntax: SyntaxNode) -> Option<Self> {
263 if Self::can_cast(syntax.kind()) {
264 Some(Self { syntax })
269 fn syntax(&self) -> &SyntaxNode {
273 impl ast::AttrsOwner for Block {}
275 pub fn statements(&self) -> AstChildren<Stmt> {
276 AstChildren::new(&self.syntax)
278 pub fn expr(&self) -> Option<Expr> {
279 AstChildren::new(&self.syntax).next()
282 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
283 pub struct BlockExpr {
284 pub(crate) syntax: SyntaxNode,
286 impl AstNode for BlockExpr {
287 fn can_cast(kind: SyntaxKind) -> bool {
293 fn cast(syntax: SyntaxNode) -> Option<Self> {
294 if Self::can_cast(syntax.kind()) {
295 Some(Self { syntax })
300 fn syntax(&self) -> &SyntaxNode {
305 pub fn block(&self) -> Option<Block> {
306 AstChildren::new(&self.syntax).next()
309 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
311 pub(crate) syntax: SyntaxNode,
313 impl AstNode for BoxExpr {
314 fn can_cast(kind: SyntaxKind) -> bool {
320 fn cast(syntax: SyntaxNode) -> Option<Self> {
321 if Self::can_cast(syntax.kind()) {
322 Some(Self { syntax })
327 fn syntax(&self) -> &SyntaxNode {
332 pub fn expr(&self) -> Option<Expr> {
333 AstChildren::new(&self.syntax).next()
336 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
338 pub(crate) syntax: SyntaxNode,
340 impl AstNode for BoxPat {
341 fn can_cast(kind: SyntaxKind) -> bool {
347 fn cast(syntax: SyntaxNode) -> Option<Self> {
348 if Self::can_cast(syntax.kind()) {
349 Some(Self { syntax })
354 fn syntax(&self) -> &SyntaxNode {
359 pub fn pat(&self) -> Option<Pat> {
360 AstChildren::new(&self.syntax).next()
363 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
364 pub struct BreakExpr {
365 pub(crate) syntax: SyntaxNode,
367 impl AstNode for BreakExpr {
368 fn can_cast(kind: SyntaxKind) -> bool {
374 fn cast(syntax: SyntaxNode) -> Option<Self> {
375 if Self::can_cast(syntax.kind()) {
376 Some(Self { syntax })
381 fn syntax(&self) -> &SyntaxNode {
386 pub fn expr(&self) -> Option<Expr> {
387 AstChildren::new(&self.syntax).next()
390 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
391 pub struct CallExpr {
392 pub(crate) syntax: SyntaxNode,
394 impl AstNode for CallExpr {
395 fn can_cast(kind: SyntaxKind) -> bool {
401 fn cast(syntax: SyntaxNode) -> Option<Self> {
402 if Self::can_cast(syntax.kind()) {
403 Some(Self { syntax })
408 fn syntax(&self) -> &SyntaxNode {
412 impl ast::ArgListOwner for CallExpr {}
414 pub fn expr(&self) -> Option<Expr> {
415 AstChildren::new(&self.syntax).next()
418 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
419 pub struct CastExpr {
420 pub(crate) syntax: SyntaxNode,
422 impl AstNode for CastExpr {
423 fn can_cast(kind: SyntaxKind) -> bool {
429 fn cast(syntax: SyntaxNode) -> Option<Self> {
430 if Self::can_cast(syntax.kind()) {
431 Some(Self { syntax })
436 fn syntax(&self) -> &SyntaxNode {
441 pub fn expr(&self) -> Option<Expr> {
442 AstChildren::new(&self.syntax).next()
444 pub fn type_ref(&self) -> Option<TypeRef> {
445 AstChildren::new(&self.syntax).next()
448 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
449 pub struct Condition {
450 pub(crate) syntax: SyntaxNode,
452 impl AstNode for Condition {
453 fn can_cast(kind: SyntaxKind) -> bool {
459 fn cast(syntax: SyntaxNode) -> Option<Self> {
460 if Self::can_cast(syntax.kind()) {
461 Some(Self { syntax })
466 fn syntax(&self) -> &SyntaxNode {
471 pub fn pat(&self) -> Option<Pat> {
472 AstChildren::new(&self.syntax).next()
474 pub fn expr(&self) -> Option<Expr> {
475 AstChildren::new(&self.syntax).next()
478 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
479 pub struct ConstDef {
480 pub(crate) syntax: SyntaxNode,
482 impl AstNode for ConstDef {
483 fn can_cast(kind: SyntaxKind) -> bool {
489 fn cast(syntax: SyntaxNode) -> Option<Self> {
490 if Self::can_cast(syntax.kind()) {
491 Some(Self { syntax })
496 fn syntax(&self) -> &SyntaxNode {
500 impl ast::VisibilityOwner for ConstDef {}
501 impl ast::NameOwner for ConstDef {}
502 impl ast::TypeParamsOwner for ConstDef {}
503 impl ast::AttrsOwner for ConstDef {}
504 impl ast::DocCommentsOwner for ConstDef {}
505 impl ast::TypeAscriptionOwner for ConstDef {}
507 pub fn body(&self) -> Option<Expr> {
508 AstChildren::new(&self.syntax).next()
511 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
512 pub struct ContinueExpr {
513 pub(crate) syntax: SyntaxNode,
515 impl AstNode for ContinueExpr {
516 fn can_cast(kind: SyntaxKind) -> bool {
518 CONTINUE_EXPR => true,
522 fn cast(syntax: SyntaxNode) -> Option<Self> {
523 if Self::can_cast(syntax.kind()) {
524 Some(Self { syntax })
529 fn syntax(&self) -> &SyntaxNode {
534 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
535 pub struct DynTraitType {
536 pub(crate) syntax: SyntaxNode,
538 impl AstNode for DynTraitType {
539 fn can_cast(kind: SyntaxKind) -> bool {
541 DYN_TRAIT_TYPE => true,
545 fn cast(syntax: SyntaxNode) -> Option<Self> {
546 if Self::can_cast(syntax.kind()) {
547 Some(Self { syntax })
552 fn syntax(&self) -> &SyntaxNode {
556 impl ast::TypeBoundsOwner for DynTraitType {}
558 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
560 pub(crate) syntax: SyntaxNode,
562 impl AstNode for EnumDef {
563 fn can_cast(kind: SyntaxKind) -> bool {
569 fn cast(syntax: SyntaxNode) -> Option<Self> {
570 if Self::can_cast(syntax.kind()) {
571 Some(Self { syntax })
576 fn syntax(&self) -> &SyntaxNode {
580 impl ast::VisibilityOwner for EnumDef {}
581 impl ast::NameOwner for EnumDef {}
582 impl ast::TypeParamsOwner for EnumDef {}
583 impl ast::AttrsOwner for EnumDef {}
584 impl ast::DocCommentsOwner for EnumDef {}
586 pub fn variant_list(&self) -> Option<EnumVariantList> {
587 AstChildren::new(&self.syntax).next()
590 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
591 pub struct EnumVariant {
592 pub(crate) syntax: SyntaxNode,
594 impl AstNode for EnumVariant {
595 fn can_cast(kind: SyntaxKind) -> bool {
597 ENUM_VARIANT => true,
601 fn cast(syntax: SyntaxNode) -> Option<Self> {
602 if Self::can_cast(syntax.kind()) {
603 Some(Self { syntax })
608 fn syntax(&self) -> &SyntaxNode {
612 impl ast::NameOwner for EnumVariant {}
613 impl ast::DocCommentsOwner for EnumVariant {}
614 impl ast::AttrsOwner for EnumVariant {}
616 pub fn expr(&self) -> Option<Expr> {
617 AstChildren::new(&self.syntax).next()
620 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
621 pub struct EnumVariantList {
622 pub(crate) syntax: SyntaxNode,
624 impl AstNode for EnumVariantList {
625 fn can_cast(kind: SyntaxKind) -> bool {
627 ENUM_VARIANT_LIST => true,
631 fn cast(syntax: SyntaxNode) -> Option<Self> {
632 if Self::can_cast(syntax.kind()) {
633 Some(Self { syntax })
638 fn syntax(&self) -> &SyntaxNode {
642 impl EnumVariantList {
643 pub fn variants(&self) -> AstChildren<EnumVariant> {
644 AstChildren::new(&self.syntax)
647 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
649 TupleExpr(TupleExpr),
650 ArrayExpr(ArrayExpr),
651 ParenExpr(ParenExpr),
653 LambdaExpr(LambdaExpr),
657 WhileExpr(WhileExpr),
658 ContinueExpr(ContinueExpr),
659 BreakExpr(BreakExpr),
661 BlockExpr(BlockExpr),
662 ReturnExpr(ReturnExpr),
663 MatchExpr(MatchExpr),
664 RecordLit(RecordLit),
666 IndexExpr(IndexExpr),
667 MethodCallExpr(MethodCallExpr),
668 FieldExpr(FieldExpr),
669 AwaitExpr(AwaitExpr),
671 TryBlockExpr(TryBlockExpr),
674 PrefixExpr(PrefixExpr),
675 RangeExpr(RangeExpr),
678 MacroCall(MacroCall),
681 impl From<TupleExpr> for Expr {
682 fn from(node: TupleExpr) -> Expr {
683 Expr::TupleExpr(node)
686 impl From<ArrayExpr> for Expr {
687 fn from(node: ArrayExpr) -> Expr {
688 Expr::ArrayExpr(node)
691 impl From<ParenExpr> for Expr {
692 fn from(node: ParenExpr) -> Expr {
693 Expr::ParenExpr(node)
696 impl From<PathExpr> for Expr {
697 fn from(node: PathExpr) -> Expr {
701 impl From<LambdaExpr> for Expr {
702 fn from(node: LambdaExpr) -> Expr {
703 Expr::LambdaExpr(node)
706 impl From<IfExpr> for Expr {
707 fn from(node: IfExpr) -> Expr {
711 impl From<LoopExpr> for Expr {
712 fn from(node: LoopExpr) -> Expr {
716 impl From<ForExpr> for Expr {
717 fn from(node: ForExpr) -> Expr {
721 impl From<WhileExpr> for Expr {
722 fn from(node: WhileExpr) -> Expr {
723 Expr::WhileExpr(node)
726 impl From<ContinueExpr> for Expr {
727 fn from(node: ContinueExpr) -> Expr {
728 Expr::ContinueExpr(node)
731 impl From<BreakExpr> for Expr {
732 fn from(node: BreakExpr) -> Expr {
733 Expr::BreakExpr(node)
736 impl From<Label> for Expr {
737 fn from(node: Label) -> Expr {
741 impl From<BlockExpr> for Expr {
742 fn from(node: BlockExpr) -> Expr {
743 Expr::BlockExpr(node)
746 impl From<ReturnExpr> for Expr {
747 fn from(node: ReturnExpr) -> Expr {
748 Expr::ReturnExpr(node)
751 impl From<MatchExpr> for Expr {
752 fn from(node: MatchExpr) -> Expr {
753 Expr::MatchExpr(node)
756 impl From<RecordLit> for Expr {
757 fn from(node: RecordLit) -> Expr {
758 Expr::RecordLit(node)
761 impl From<CallExpr> for Expr {
762 fn from(node: CallExpr) -> Expr {
766 impl From<IndexExpr> for Expr {
767 fn from(node: IndexExpr) -> Expr {
768 Expr::IndexExpr(node)
771 impl From<MethodCallExpr> for Expr {
772 fn from(node: MethodCallExpr) -> Expr {
773 Expr::MethodCallExpr(node)
776 impl From<FieldExpr> for Expr {
777 fn from(node: FieldExpr) -> Expr {
778 Expr::FieldExpr(node)
781 impl From<AwaitExpr> for Expr {
782 fn from(node: AwaitExpr) -> Expr {
783 Expr::AwaitExpr(node)
786 impl From<TryExpr> for Expr {
787 fn from(node: TryExpr) -> Expr {
791 impl From<TryBlockExpr> for Expr {
792 fn from(node: TryBlockExpr) -> Expr {
793 Expr::TryBlockExpr(node)
796 impl From<CastExpr> for Expr {
797 fn from(node: CastExpr) -> Expr {
801 impl From<RefExpr> for Expr {
802 fn from(node: RefExpr) -> Expr {
806 impl From<PrefixExpr> for Expr {
807 fn from(node: PrefixExpr) -> Expr {
808 Expr::PrefixExpr(node)
811 impl From<RangeExpr> for Expr {
812 fn from(node: RangeExpr) -> Expr {
813 Expr::RangeExpr(node)
816 impl From<BinExpr> for Expr {
817 fn from(node: BinExpr) -> Expr {
821 impl From<Literal> for Expr {
822 fn from(node: Literal) -> Expr {
826 impl From<MacroCall> for Expr {
827 fn from(node: MacroCall) -> Expr {
828 Expr::MacroCall(node)
831 impl From<BoxExpr> for Expr {
832 fn from(node: BoxExpr) -> Expr {
836 impl AstNode for Expr {
837 fn can_cast(kind: SyntaxKind) -> bool {
839 TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR
840 | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL
841 | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | RECORD_LIT | CALL_EXPR | INDEX_EXPR
842 | METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | TRY_BLOCK_EXPR
843 | CAST_EXPR | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL
848 fn cast(syntax: SyntaxNode) -> Option<Self> {
849 let res = match syntax.kind() {
850 TUPLE_EXPR => Expr::TupleExpr(TupleExpr { syntax }),
851 ARRAY_EXPR => Expr::ArrayExpr(ArrayExpr { syntax }),
852 PAREN_EXPR => Expr::ParenExpr(ParenExpr { syntax }),
853 PATH_EXPR => Expr::PathExpr(PathExpr { syntax }),
854 LAMBDA_EXPR => Expr::LambdaExpr(LambdaExpr { syntax }),
855 IF_EXPR => Expr::IfExpr(IfExpr { syntax }),
856 LOOP_EXPR => Expr::LoopExpr(LoopExpr { syntax }),
857 FOR_EXPR => Expr::ForExpr(ForExpr { syntax }),
858 WHILE_EXPR => Expr::WhileExpr(WhileExpr { syntax }),
859 CONTINUE_EXPR => Expr::ContinueExpr(ContinueExpr { syntax }),
860 BREAK_EXPR => Expr::BreakExpr(BreakExpr { syntax }),
861 LABEL => Expr::Label(Label { syntax }),
862 BLOCK_EXPR => Expr::BlockExpr(BlockExpr { syntax }),
863 RETURN_EXPR => Expr::ReturnExpr(ReturnExpr { syntax }),
864 MATCH_EXPR => Expr::MatchExpr(MatchExpr { syntax }),
865 RECORD_LIT => Expr::RecordLit(RecordLit { syntax }),
866 CALL_EXPR => Expr::CallExpr(CallExpr { syntax }),
867 INDEX_EXPR => Expr::IndexExpr(IndexExpr { syntax }),
868 METHOD_CALL_EXPR => Expr::MethodCallExpr(MethodCallExpr { syntax }),
869 FIELD_EXPR => Expr::FieldExpr(FieldExpr { syntax }),
870 AWAIT_EXPR => Expr::AwaitExpr(AwaitExpr { syntax }),
871 TRY_EXPR => Expr::TryExpr(TryExpr { syntax }),
872 TRY_BLOCK_EXPR => Expr::TryBlockExpr(TryBlockExpr { syntax }),
873 CAST_EXPR => Expr::CastExpr(CastExpr { syntax }),
874 REF_EXPR => Expr::RefExpr(RefExpr { syntax }),
875 PREFIX_EXPR => Expr::PrefixExpr(PrefixExpr { syntax }),
876 RANGE_EXPR => Expr::RangeExpr(RangeExpr { syntax }),
877 BIN_EXPR => Expr::BinExpr(BinExpr { syntax }),
878 LITERAL => Expr::Literal(Literal { syntax }),
879 MACRO_CALL => Expr::MacroCall(MacroCall { syntax }),
880 BOX_EXPR => Expr::BoxExpr(BoxExpr { syntax }),
885 fn syntax(&self) -> &SyntaxNode {
887 Expr::TupleExpr(it) => &it.syntax,
888 Expr::ArrayExpr(it) => &it.syntax,
889 Expr::ParenExpr(it) => &it.syntax,
890 Expr::PathExpr(it) => &it.syntax,
891 Expr::LambdaExpr(it) => &it.syntax,
892 Expr::IfExpr(it) => &it.syntax,
893 Expr::LoopExpr(it) => &it.syntax,
894 Expr::ForExpr(it) => &it.syntax,
895 Expr::WhileExpr(it) => &it.syntax,
896 Expr::ContinueExpr(it) => &it.syntax,
897 Expr::BreakExpr(it) => &it.syntax,
898 Expr::Label(it) => &it.syntax,
899 Expr::BlockExpr(it) => &it.syntax,
900 Expr::ReturnExpr(it) => &it.syntax,
901 Expr::MatchExpr(it) => &it.syntax,
902 Expr::RecordLit(it) => &it.syntax,
903 Expr::CallExpr(it) => &it.syntax,
904 Expr::IndexExpr(it) => &it.syntax,
905 Expr::MethodCallExpr(it) => &it.syntax,
906 Expr::FieldExpr(it) => &it.syntax,
907 Expr::AwaitExpr(it) => &it.syntax,
908 Expr::TryExpr(it) => &it.syntax,
909 Expr::TryBlockExpr(it) => &it.syntax,
910 Expr::CastExpr(it) => &it.syntax,
911 Expr::RefExpr(it) => &it.syntax,
912 Expr::PrefixExpr(it) => &it.syntax,
913 Expr::RangeExpr(it) => &it.syntax,
914 Expr::BinExpr(it) => &it.syntax,
915 Expr::Literal(it) => &it.syntax,
916 Expr::MacroCall(it) => &it.syntax,
917 Expr::BoxExpr(it) => &it.syntax,
922 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
923 pub struct ExprStmt {
924 pub(crate) syntax: SyntaxNode,
926 impl AstNode for ExprStmt {
927 fn can_cast(kind: SyntaxKind) -> bool {
933 fn cast(syntax: SyntaxNode) -> Option<Self> {
934 if Self::can_cast(syntax.kind()) {
935 Some(Self { syntax })
940 fn syntax(&self) -> &SyntaxNode {
945 pub fn expr(&self) -> Option<Expr> {
946 AstChildren::new(&self.syntax).next()
949 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
950 pub struct ExternCrateItem {
951 pub(crate) syntax: SyntaxNode,
953 impl AstNode for ExternCrateItem {
954 fn can_cast(kind: SyntaxKind) -> bool {
956 EXTERN_CRATE_ITEM => true,
960 fn cast(syntax: SyntaxNode) -> Option<Self> {
961 if Self::can_cast(syntax.kind()) {
962 Some(Self { syntax })
967 fn syntax(&self) -> &SyntaxNode {
971 impl ast::AttrsOwner for ExternCrateItem {}
972 impl ExternCrateItem {
973 pub fn name_ref(&self) -> Option<NameRef> {
974 AstChildren::new(&self.syntax).next()
976 pub fn alias(&self) -> Option<Alias> {
977 AstChildren::new(&self.syntax).next()
980 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
981 pub struct FieldExpr {
982 pub(crate) syntax: SyntaxNode,
984 impl AstNode for FieldExpr {
985 fn can_cast(kind: SyntaxKind) -> bool {
991 fn cast(syntax: SyntaxNode) -> Option<Self> {
992 if Self::can_cast(syntax.kind()) {
993 Some(Self { syntax })
998 fn syntax(&self) -> &SyntaxNode {
1003 pub fn expr(&self) -> Option<Expr> {
1004 AstChildren::new(&self.syntax).next()
1006 pub fn name_ref(&self) -> Option<NameRef> {
1007 AstChildren::new(&self.syntax).next()
1010 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1012 pub(crate) syntax: SyntaxNode,
1014 impl AstNode for FnDef {
1015 fn can_cast(kind: SyntaxKind) -> bool {
1021 fn cast(syntax: SyntaxNode) -> Option<Self> {
1022 if Self::can_cast(syntax.kind()) {
1023 Some(Self { syntax })
1028 fn syntax(&self) -> &SyntaxNode {
1032 impl ast::VisibilityOwner for FnDef {}
1033 impl ast::NameOwner for FnDef {}
1034 impl ast::TypeParamsOwner for FnDef {}
1035 impl ast::AttrsOwner for FnDef {}
1036 impl ast::DocCommentsOwner for FnDef {}
1038 pub fn param_list(&self) -> Option<ParamList> {
1039 AstChildren::new(&self.syntax).next()
1041 pub fn body(&self) -> Option<BlockExpr> {
1042 AstChildren::new(&self.syntax).next()
1044 pub fn ret_type(&self) -> Option<RetType> {
1045 AstChildren::new(&self.syntax).next()
1048 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1049 pub struct FnPointerType {
1050 pub(crate) syntax: SyntaxNode,
1052 impl AstNode for FnPointerType {
1053 fn can_cast(kind: SyntaxKind) -> bool {
1055 FN_POINTER_TYPE => true,
1059 fn cast(syntax: SyntaxNode) -> Option<Self> {
1060 if Self::can_cast(syntax.kind()) {
1061 Some(Self { syntax })
1066 fn syntax(&self) -> &SyntaxNode {
1070 impl FnPointerType {
1071 pub fn param_list(&self) -> Option<ParamList> {
1072 AstChildren::new(&self.syntax).next()
1074 pub fn ret_type(&self) -> Option<RetType> {
1075 AstChildren::new(&self.syntax).next()
1078 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1079 pub struct ForExpr {
1080 pub(crate) syntax: SyntaxNode,
1082 impl AstNode for ForExpr {
1083 fn can_cast(kind: SyntaxKind) -> bool {
1089 fn cast(syntax: SyntaxNode) -> Option<Self> {
1090 if Self::can_cast(syntax.kind()) {
1091 Some(Self { syntax })
1096 fn syntax(&self) -> &SyntaxNode {
1100 impl ast::LoopBodyOwner for ForExpr {}
1102 pub fn pat(&self) -> Option<Pat> {
1103 AstChildren::new(&self.syntax).next()
1105 pub fn iterable(&self) -> Option<Expr> {
1106 AstChildren::new(&self.syntax).next()
1109 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1110 pub struct ForType {
1111 pub(crate) syntax: SyntaxNode,
1113 impl AstNode for ForType {
1114 fn can_cast(kind: SyntaxKind) -> bool {
1120 fn cast(syntax: SyntaxNode) -> Option<Self> {
1121 if Self::can_cast(syntax.kind()) {
1122 Some(Self { syntax })
1127 fn syntax(&self) -> &SyntaxNode {
1132 pub fn type_ref(&self) -> Option<TypeRef> {
1133 AstChildren::new(&self.syntax).next()
1136 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1138 pub(crate) syntax: SyntaxNode,
1140 impl AstNode for IfExpr {
1141 fn can_cast(kind: SyntaxKind) -> bool {
1147 fn cast(syntax: SyntaxNode) -> Option<Self> {
1148 if Self::can_cast(syntax.kind()) {
1149 Some(Self { syntax })
1154 fn syntax(&self) -> &SyntaxNode {
1159 pub fn condition(&self) -> Option<Condition> {
1160 AstChildren::new(&self.syntax).next()
1163 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1164 pub struct ImplBlock {
1165 pub(crate) syntax: SyntaxNode,
1167 impl AstNode for ImplBlock {
1168 fn can_cast(kind: SyntaxKind) -> bool {
1174 fn cast(syntax: SyntaxNode) -> Option<Self> {
1175 if Self::can_cast(syntax.kind()) {
1176 Some(Self { syntax })
1181 fn syntax(&self) -> &SyntaxNode {
1185 impl ast::TypeParamsOwner for ImplBlock {}
1186 impl ast::AttrsOwner for ImplBlock {}
1188 pub fn item_list(&self) -> Option<ItemList> {
1189 AstChildren::new(&self.syntax).next()
1192 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1195 TypeAliasDef(TypeAliasDef),
1198 impl From<FnDef> for ImplItem {
1199 fn from(node: FnDef) -> ImplItem {
1200 ImplItem::FnDef(node)
1203 impl From<TypeAliasDef> for ImplItem {
1204 fn from(node: TypeAliasDef) -> ImplItem {
1205 ImplItem::TypeAliasDef(node)
1208 impl From<ConstDef> for ImplItem {
1209 fn from(node: ConstDef) -> ImplItem {
1210 ImplItem::ConstDef(node)
1213 impl AstNode for ImplItem {
1214 fn can_cast(kind: SyntaxKind) -> bool {
1216 FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true,
1220 fn cast(syntax: SyntaxNode) -> Option<Self> {
1221 let res = match syntax.kind() {
1222 FN_DEF => ImplItem::FnDef(FnDef { syntax }),
1223 TYPE_ALIAS_DEF => ImplItem::TypeAliasDef(TypeAliasDef { syntax }),
1224 CONST_DEF => ImplItem::ConstDef(ConstDef { syntax }),
1229 fn syntax(&self) -> &SyntaxNode {
1231 ImplItem::FnDef(it) => &it.syntax,
1232 ImplItem::TypeAliasDef(it) => &it.syntax,
1233 ImplItem::ConstDef(it) => &it.syntax,
1238 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1239 pub struct ImplTraitType {
1240 pub(crate) syntax: SyntaxNode,
1242 impl AstNode for ImplTraitType {
1243 fn can_cast(kind: SyntaxKind) -> bool {
1245 IMPL_TRAIT_TYPE => true,
1249 fn cast(syntax: SyntaxNode) -> Option<Self> {
1250 if Self::can_cast(syntax.kind()) {
1251 Some(Self { syntax })
1256 fn syntax(&self) -> &SyntaxNode {
1260 impl ast::TypeBoundsOwner for ImplTraitType {}
1261 impl ImplTraitType {}
1262 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1263 pub struct IndexExpr {
1264 pub(crate) syntax: SyntaxNode,
1266 impl AstNode for IndexExpr {
1267 fn can_cast(kind: SyntaxKind) -> bool {
1273 fn cast(syntax: SyntaxNode) -> Option<Self> {
1274 if Self::can_cast(syntax.kind()) {
1275 Some(Self { syntax })
1280 fn syntax(&self) -> &SyntaxNode {
1285 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1286 pub struct ItemList {
1287 pub(crate) syntax: SyntaxNode,
1289 impl AstNode for ItemList {
1290 fn can_cast(kind: SyntaxKind) -> bool {
1296 fn cast(syntax: SyntaxNode) -> Option<Self> {
1297 if Self::can_cast(syntax.kind()) {
1298 Some(Self { syntax })
1303 fn syntax(&self) -> &SyntaxNode {
1307 impl ast::FnDefOwner for ItemList {}
1308 impl ast::ModuleItemOwner for ItemList {}
1310 pub fn impl_items(&self) -> AstChildren<ImplItem> {
1311 AstChildren::new(&self.syntax)
1314 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1316 pub(crate) syntax: SyntaxNode,
1318 impl AstNode for Label {
1319 fn can_cast(kind: SyntaxKind) -> bool {
1325 fn cast(syntax: SyntaxNode) -> Option<Self> {
1326 if Self::can_cast(syntax.kind()) {
1327 Some(Self { syntax })
1332 fn syntax(&self) -> &SyntaxNode {
1337 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1338 pub struct LambdaExpr {
1339 pub(crate) syntax: SyntaxNode,
1341 impl AstNode for LambdaExpr {
1342 fn can_cast(kind: SyntaxKind) -> bool {
1344 LAMBDA_EXPR => true,
1348 fn cast(syntax: SyntaxNode) -> Option<Self> {
1349 if Self::can_cast(syntax.kind()) {
1350 Some(Self { syntax })
1355 fn syntax(&self) -> &SyntaxNode {
1360 pub fn param_list(&self) -> Option<ParamList> {
1361 AstChildren::new(&self.syntax).next()
1363 pub fn body(&self) -> Option<Expr> {
1364 AstChildren::new(&self.syntax).next()
1367 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1368 pub struct LetStmt {
1369 pub(crate) syntax: SyntaxNode,
1371 impl AstNode for LetStmt {
1372 fn can_cast(kind: SyntaxKind) -> bool {
1378 fn cast(syntax: SyntaxNode) -> Option<Self> {
1379 if Self::can_cast(syntax.kind()) {
1380 Some(Self { syntax })
1385 fn syntax(&self) -> &SyntaxNode {
1389 impl ast::TypeAscriptionOwner for LetStmt {}
1391 pub fn pat(&self) -> Option<Pat> {
1392 AstChildren::new(&self.syntax).next()
1394 pub fn initializer(&self) -> Option<Expr> {
1395 AstChildren::new(&self.syntax).next()
1398 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1399 pub struct LifetimeArg {
1400 pub(crate) syntax: SyntaxNode,
1402 impl AstNode for LifetimeArg {
1403 fn can_cast(kind: SyntaxKind) -> bool {
1405 LIFETIME_ARG => true,
1409 fn cast(syntax: SyntaxNode) -> Option<Self> {
1410 if Self::can_cast(syntax.kind()) {
1411 Some(Self { syntax })
1416 fn syntax(&self) -> &SyntaxNode {
1421 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1422 pub struct LifetimeParam {
1423 pub(crate) syntax: SyntaxNode,
1425 impl AstNode for LifetimeParam {
1426 fn can_cast(kind: SyntaxKind) -> bool {
1428 LIFETIME_PARAM => true,
1432 fn cast(syntax: SyntaxNode) -> Option<Self> {
1433 if Self::can_cast(syntax.kind()) {
1434 Some(Self { syntax })
1439 fn syntax(&self) -> &SyntaxNode {
1443 impl ast::AttrsOwner for LifetimeParam {}
1444 impl LifetimeParam {}
1445 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1446 pub struct Literal {
1447 pub(crate) syntax: SyntaxNode,
1449 impl AstNode for Literal {
1450 fn can_cast(kind: SyntaxKind) -> bool {
1456 fn cast(syntax: SyntaxNode) -> Option<Self> {
1457 if Self::can_cast(syntax.kind()) {
1458 Some(Self { syntax })
1463 fn syntax(&self) -> &SyntaxNode {
1468 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1469 pub struct LiteralPat {
1470 pub(crate) syntax: SyntaxNode,
1472 impl AstNode for LiteralPat {
1473 fn can_cast(kind: SyntaxKind) -> bool {
1475 LITERAL_PAT => true,
1479 fn cast(syntax: SyntaxNode) -> Option<Self> {
1480 if Self::can_cast(syntax.kind()) {
1481 Some(Self { syntax })
1486 fn syntax(&self) -> &SyntaxNode {
1491 pub fn literal(&self) -> Option<Literal> {
1492 AstChildren::new(&self.syntax).next()
1495 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1496 pub struct LoopExpr {
1497 pub(crate) syntax: SyntaxNode,
1499 impl AstNode for LoopExpr {
1500 fn can_cast(kind: SyntaxKind) -> bool {
1506 fn cast(syntax: SyntaxNode) -> Option<Self> {
1507 if Self::can_cast(syntax.kind()) {
1508 Some(Self { syntax })
1513 fn syntax(&self) -> &SyntaxNode {
1517 impl ast::LoopBodyOwner for LoopExpr {}
1519 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1520 pub struct MacroCall {
1521 pub(crate) syntax: SyntaxNode,
1523 impl AstNode for MacroCall {
1524 fn can_cast(kind: SyntaxKind) -> bool {
1530 fn cast(syntax: SyntaxNode) -> Option<Self> {
1531 if Self::can_cast(syntax.kind()) {
1532 Some(Self { syntax })
1537 fn syntax(&self) -> &SyntaxNode {
1541 impl ast::NameOwner for MacroCall {}
1542 impl ast::AttrsOwner for MacroCall {}
1543 impl ast::DocCommentsOwner for MacroCall {}
1545 pub fn token_tree(&self) -> Option<TokenTree> {
1546 AstChildren::new(&self.syntax).next()
1548 pub fn path(&self) -> Option<Path> {
1549 AstChildren::new(&self.syntax).next()
1552 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1553 pub struct MacroItems {
1554 pub(crate) syntax: SyntaxNode,
1556 impl AstNode for MacroItems {
1557 fn can_cast(kind: SyntaxKind) -> bool {
1559 MACRO_ITEMS => true,
1563 fn cast(syntax: SyntaxNode) -> Option<Self> {
1564 if Self::can_cast(syntax.kind()) {
1565 Some(Self { syntax })
1570 fn syntax(&self) -> &SyntaxNode {
1574 impl ast::ModuleItemOwner for MacroItems {}
1575 impl ast::FnDefOwner for MacroItems {}
1577 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1578 pub struct MacroStmts {
1579 pub(crate) syntax: SyntaxNode,
1581 impl AstNode for MacroStmts {
1582 fn can_cast(kind: SyntaxKind) -> bool {
1584 MACRO_STMTS => true,
1588 fn cast(syntax: SyntaxNode) -> Option<Self> {
1589 if Self::can_cast(syntax.kind()) {
1590 Some(Self { syntax })
1595 fn syntax(&self) -> &SyntaxNode {
1600 pub fn statements(&self) -> AstChildren<Stmt> {
1601 AstChildren::new(&self.syntax)
1603 pub fn expr(&self) -> Option<Expr> {
1604 AstChildren::new(&self.syntax).next()
1607 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1608 pub struct MatchArm {
1609 pub(crate) syntax: SyntaxNode,
1611 impl AstNode for MatchArm {
1612 fn can_cast(kind: SyntaxKind) -> bool {
1618 fn cast(syntax: SyntaxNode) -> Option<Self> {
1619 if Self::can_cast(syntax.kind()) {
1620 Some(Self { syntax })
1625 fn syntax(&self) -> &SyntaxNode {
1629 impl ast::AttrsOwner for MatchArm {}
1631 pub fn pats(&self) -> AstChildren<Pat> {
1632 AstChildren::new(&self.syntax)
1634 pub fn guard(&self) -> Option<MatchGuard> {
1635 AstChildren::new(&self.syntax).next()
1637 pub fn expr(&self) -> Option<Expr> {
1638 AstChildren::new(&self.syntax).next()
1641 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1642 pub struct MatchArmList {
1643 pub(crate) syntax: SyntaxNode,
1645 impl AstNode for MatchArmList {
1646 fn can_cast(kind: SyntaxKind) -> bool {
1648 MATCH_ARM_LIST => true,
1652 fn cast(syntax: SyntaxNode) -> Option<Self> {
1653 if Self::can_cast(syntax.kind()) {
1654 Some(Self { syntax })
1659 fn syntax(&self) -> &SyntaxNode {
1663 impl ast::AttrsOwner for MatchArmList {}
1665 pub fn arms(&self) -> AstChildren<MatchArm> {
1666 AstChildren::new(&self.syntax)
1669 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1670 pub struct MatchExpr {
1671 pub(crate) syntax: SyntaxNode,
1673 impl AstNode for MatchExpr {
1674 fn can_cast(kind: SyntaxKind) -> bool {
1680 fn cast(syntax: SyntaxNode) -> Option<Self> {
1681 if Self::can_cast(syntax.kind()) {
1682 Some(Self { syntax })
1687 fn syntax(&self) -> &SyntaxNode {
1692 pub fn expr(&self) -> Option<Expr> {
1693 AstChildren::new(&self.syntax).next()
1695 pub fn match_arm_list(&self) -> Option<MatchArmList> {
1696 AstChildren::new(&self.syntax).next()
1699 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1700 pub struct MatchGuard {
1701 pub(crate) syntax: SyntaxNode,
1703 impl AstNode for MatchGuard {
1704 fn can_cast(kind: SyntaxKind) -> bool {
1706 MATCH_GUARD => true,
1710 fn cast(syntax: SyntaxNode) -> Option<Self> {
1711 if Self::can_cast(syntax.kind()) {
1712 Some(Self { syntax })
1717 fn syntax(&self) -> &SyntaxNode {
1722 pub fn expr(&self) -> Option<Expr> {
1723 AstChildren::new(&self.syntax).next()
1726 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1727 pub struct MethodCallExpr {
1728 pub(crate) syntax: SyntaxNode,
1730 impl AstNode for MethodCallExpr {
1731 fn can_cast(kind: SyntaxKind) -> bool {
1733 METHOD_CALL_EXPR => true,
1737 fn cast(syntax: SyntaxNode) -> Option<Self> {
1738 if Self::can_cast(syntax.kind()) {
1739 Some(Self { syntax })
1744 fn syntax(&self) -> &SyntaxNode {
1748 impl ast::ArgListOwner for MethodCallExpr {}
1749 impl MethodCallExpr {
1750 pub fn expr(&self) -> Option<Expr> {
1751 AstChildren::new(&self.syntax).next()
1753 pub fn name_ref(&self) -> Option<NameRef> {
1754 AstChildren::new(&self.syntax).next()
1756 pub fn type_arg_list(&self) -> Option<TypeArgList> {
1757 AstChildren::new(&self.syntax).next()
1760 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1762 pub(crate) syntax: SyntaxNode,
1764 impl AstNode for Module {
1765 fn can_cast(kind: SyntaxKind) -> bool {
1771 fn cast(syntax: SyntaxNode) -> Option<Self> {
1772 if Self::can_cast(syntax.kind()) {
1773 Some(Self { syntax })
1778 fn syntax(&self) -> &SyntaxNode {
1782 impl ast::VisibilityOwner for Module {}
1783 impl ast::NameOwner for Module {}
1784 impl ast::AttrsOwner for Module {}
1785 impl ast::DocCommentsOwner for Module {}
1787 pub fn item_list(&self) -> Option<ItemList> {
1788 AstChildren::new(&self.syntax).next()
1791 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1792 pub enum ModuleItem {
1793 StructDef(StructDef),
1797 TypeAliasDef(TypeAliasDef),
1798 ImplBlock(ImplBlock),
1800 ExternCrateItem(ExternCrateItem),
1802 StaticDef(StaticDef),
1805 impl From<StructDef> for ModuleItem {
1806 fn from(node: StructDef) -> ModuleItem {
1807 ModuleItem::StructDef(node)
1810 impl From<EnumDef> for ModuleItem {
1811 fn from(node: EnumDef) -> ModuleItem {
1812 ModuleItem::EnumDef(node)
1815 impl From<FnDef> for ModuleItem {
1816 fn from(node: FnDef) -> ModuleItem {
1817 ModuleItem::FnDef(node)
1820 impl From<TraitDef> for ModuleItem {
1821 fn from(node: TraitDef) -> ModuleItem {
1822 ModuleItem::TraitDef(node)
1825 impl From<TypeAliasDef> for ModuleItem {
1826 fn from(node: TypeAliasDef) -> ModuleItem {
1827 ModuleItem::TypeAliasDef(node)
1830 impl From<ImplBlock> for ModuleItem {
1831 fn from(node: ImplBlock) -> ModuleItem {
1832 ModuleItem::ImplBlock(node)
1835 impl From<UseItem> for ModuleItem {
1836 fn from(node: UseItem) -> ModuleItem {
1837 ModuleItem::UseItem(node)
1840 impl From<ExternCrateItem> for ModuleItem {
1841 fn from(node: ExternCrateItem) -> ModuleItem {
1842 ModuleItem::ExternCrateItem(node)
1845 impl From<ConstDef> for ModuleItem {
1846 fn from(node: ConstDef) -> ModuleItem {
1847 ModuleItem::ConstDef(node)
1850 impl From<StaticDef> for ModuleItem {
1851 fn from(node: StaticDef) -> ModuleItem {
1852 ModuleItem::StaticDef(node)
1855 impl From<Module> for ModuleItem {
1856 fn from(node: Module) -> ModuleItem {
1857 ModuleItem::Module(node)
1860 impl AstNode for ModuleItem {
1861 fn can_cast(kind: SyntaxKind) -> bool {
1863 STRUCT_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_BLOCK | USE_ITEM
1864 | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE => true,
1868 fn cast(syntax: SyntaxNode) -> Option<Self> {
1869 let res = match syntax.kind() {
1870 STRUCT_DEF => ModuleItem::StructDef(StructDef { syntax }),
1871 ENUM_DEF => ModuleItem::EnumDef(EnumDef { syntax }),
1872 FN_DEF => ModuleItem::FnDef(FnDef { syntax }),
1873 TRAIT_DEF => ModuleItem::TraitDef(TraitDef { syntax }),
1874 TYPE_ALIAS_DEF => ModuleItem::TypeAliasDef(TypeAliasDef { syntax }),
1875 IMPL_BLOCK => ModuleItem::ImplBlock(ImplBlock { syntax }),
1876 USE_ITEM => ModuleItem::UseItem(UseItem { syntax }),
1877 EXTERN_CRATE_ITEM => ModuleItem::ExternCrateItem(ExternCrateItem { syntax }),
1878 CONST_DEF => ModuleItem::ConstDef(ConstDef { syntax }),
1879 STATIC_DEF => ModuleItem::StaticDef(StaticDef { syntax }),
1880 MODULE => ModuleItem::Module(Module { syntax }),
1885 fn syntax(&self) -> &SyntaxNode {
1887 ModuleItem::StructDef(it) => &it.syntax,
1888 ModuleItem::EnumDef(it) => &it.syntax,
1889 ModuleItem::FnDef(it) => &it.syntax,
1890 ModuleItem::TraitDef(it) => &it.syntax,
1891 ModuleItem::TypeAliasDef(it) => &it.syntax,
1892 ModuleItem::ImplBlock(it) => &it.syntax,
1893 ModuleItem::UseItem(it) => &it.syntax,
1894 ModuleItem::ExternCrateItem(it) => &it.syntax,
1895 ModuleItem::ConstDef(it) => &it.syntax,
1896 ModuleItem::StaticDef(it) => &it.syntax,
1897 ModuleItem::Module(it) => &it.syntax,
1902 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1904 pub(crate) syntax: SyntaxNode,
1906 impl AstNode for Name {
1907 fn can_cast(kind: SyntaxKind) -> bool {
1913 fn cast(syntax: SyntaxNode) -> Option<Self> {
1914 if Self::can_cast(syntax.kind()) {
1915 Some(Self { syntax })
1920 fn syntax(&self) -> &SyntaxNode {
1925 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1926 pub struct NameRef {
1927 pub(crate) syntax: SyntaxNode,
1929 impl AstNode for NameRef {
1930 fn can_cast(kind: SyntaxKind) -> bool {
1936 fn cast(syntax: SyntaxNode) -> Option<Self> {
1937 if Self::can_cast(syntax.kind()) {
1938 Some(Self { syntax })
1943 fn syntax(&self) -> &SyntaxNode {
1948 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1949 pub struct NeverType {
1950 pub(crate) syntax: SyntaxNode,
1952 impl AstNode for NeverType {
1953 fn can_cast(kind: SyntaxKind) -> bool {
1959 fn cast(syntax: SyntaxNode) -> Option<Self> {
1960 if Self::can_cast(syntax.kind()) {
1961 Some(Self { syntax })
1966 fn syntax(&self) -> &SyntaxNode {
1971 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1972 pub enum NominalDef {
1973 StructDef(StructDef),
1976 impl From<StructDef> for NominalDef {
1977 fn from(node: StructDef) -> NominalDef {
1978 NominalDef::StructDef(node)
1981 impl From<EnumDef> for NominalDef {
1982 fn from(node: EnumDef) -> NominalDef {
1983 NominalDef::EnumDef(node)
1986 impl AstNode for NominalDef {
1987 fn can_cast(kind: SyntaxKind) -> bool {
1989 STRUCT_DEF | ENUM_DEF => true,
1993 fn cast(syntax: SyntaxNode) -> Option<Self> {
1994 let res = match syntax.kind() {
1995 STRUCT_DEF => NominalDef::StructDef(StructDef { syntax }),
1996 ENUM_DEF => NominalDef::EnumDef(EnumDef { syntax }),
2001 fn syntax(&self) -> &SyntaxNode {
2003 NominalDef::StructDef(it) => &it.syntax,
2004 NominalDef::EnumDef(it) => &it.syntax,
2008 impl ast::NameOwner for NominalDef {}
2009 impl ast::TypeParamsOwner for NominalDef {}
2010 impl ast::AttrsOwner for NominalDef {}
2012 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2014 pub(crate) syntax: SyntaxNode,
2016 impl AstNode for Param {
2017 fn can_cast(kind: SyntaxKind) -> bool {
2023 fn cast(syntax: SyntaxNode) -> Option<Self> {
2024 if Self::can_cast(syntax.kind()) {
2025 Some(Self { syntax })
2030 fn syntax(&self) -> &SyntaxNode {
2034 impl ast::TypeAscriptionOwner for Param {}
2035 impl ast::AttrsOwner for Param {}
2037 pub fn pat(&self) -> Option<Pat> {
2038 AstChildren::new(&self.syntax).next()
2041 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2042 pub struct ParamList {
2043 pub(crate) syntax: SyntaxNode,
2045 impl AstNode for ParamList {
2046 fn can_cast(kind: SyntaxKind) -> bool {
2052 fn cast(syntax: SyntaxNode) -> Option<Self> {
2053 if Self::can_cast(syntax.kind()) {
2054 Some(Self { syntax })
2059 fn syntax(&self) -> &SyntaxNode {
2064 pub fn params(&self) -> AstChildren<Param> {
2065 AstChildren::new(&self.syntax)
2067 pub fn self_param(&self) -> Option<SelfParam> {
2068 AstChildren::new(&self.syntax).next()
2071 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2072 pub struct ParenExpr {
2073 pub(crate) syntax: SyntaxNode,
2075 impl AstNode for ParenExpr {
2076 fn can_cast(kind: SyntaxKind) -> bool {
2082 fn cast(syntax: SyntaxNode) -> Option<Self> {
2083 if Self::can_cast(syntax.kind()) {
2084 Some(Self { syntax })
2089 fn syntax(&self) -> &SyntaxNode {
2094 pub fn expr(&self) -> Option<Expr> {
2095 AstChildren::new(&self.syntax).next()
2098 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2099 pub struct ParenType {
2100 pub(crate) syntax: SyntaxNode,
2102 impl AstNode for ParenType {
2103 fn can_cast(kind: SyntaxKind) -> bool {
2109 fn cast(syntax: SyntaxNode) -> Option<Self> {
2110 if Self::can_cast(syntax.kind()) {
2111 Some(Self { syntax })
2116 fn syntax(&self) -> &SyntaxNode {
2121 pub fn type_ref(&self) -> Option<TypeRef> {
2122 AstChildren::new(&self.syntax).next()
2125 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2130 PlaceholderPat(PlaceholderPat),
2132 RecordPat(RecordPat),
2133 TupleStructPat(TupleStructPat),
2137 LiteralPat(LiteralPat),
2139 impl From<RefPat> for Pat {
2140 fn from(node: RefPat) -> Pat {
2144 impl From<BoxPat> for Pat {
2145 fn from(node: BoxPat) -> Pat {
2149 impl From<BindPat> for Pat {
2150 fn from(node: BindPat) -> Pat {
2154 impl From<PlaceholderPat> for Pat {
2155 fn from(node: PlaceholderPat) -> Pat {
2156 Pat::PlaceholderPat(node)
2159 impl From<PathPat> for Pat {
2160 fn from(node: PathPat) -> Pat {
2164 impl From<RecordPat> for Pat {
2165 fn from(node: RecordPat) -> Pat {
2166 Pat::RecordPat(node)
2169 impl From<TupleStructPat> for Pat {
2170 fn from(node: TupleStructPat) -> Pat {
2171 Pat::TupleStructPat(node)
2174 impl From<TuplePat> for Pat {
2175 fn from(node: TuplePat) -> Pat {
2179 impl From<SlicePat> for Pat {
2180 fn from(node: SlicePat) -> Pat {
2184 impl From<RangePat> for Pat {
2185 fn from(node: RangePat) -> Pat {
2189 impl From<LiteralPat> for Pat {
2190 fn from(node: LiteralPat) -> Pat {
2191 Pat::LiteralPat(node)
2194 impl AstNode for Pat {
2195 fn can_cast(kind: SyntaxKind) -> bool {
2197 REF_PAT | BOX_PAT | BIND_PAT | PLACEHOLDER_PAT | PATH_PAT | RECORD_PAT
2198 | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => true,
2202 fn cast(syntax: SyntaxNode) -> Option<Self> {
2203 let res = match syntax.kind() {
2204 REF_PAT => Pat::RefPat(RefPat { syntax }),
2205 BOX_PAT => Pat::BoxPat(BoxPat { syntax }),
2206 BIND_PAT => Pat::BindPat(BindPat { syntax }),
2207 PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }),
2208 PATH_PAT => Pat::PathPat(PathPat { syntax }),
2209 RECORD_PAT => Pat::RecordPat(RecordPat { syntax }),
2210 TUPLE_STRUCT_PAT => Pat::TupleStructPat(TupleStructPat { syntax }),
2211 TUPLE_PAT => Pat::TuplePat(TuplePat { syntax }),
2212 SLICE_PAT => Pat::SlicePat(SlicePat { syntax }),
2213 RANGE_PAT => Pat::RangePat(RangePat { syntax }),
2214 LITERAL_PAT => Pat::LiteralPat(LiteralPat { syntax }),
2219 fn syntax(&self) -> &SyntaxNode {
2221 Pat::RefPat(it) => &it.syntax,
2222 Pat::BoxPat(it) => &it.syntax,
2223 Pat::BindPat(it) => &it.syntax,
2224 Pat::PlaceholderPat(it) => &it.syntax,
2225 Pat::PathPat(it) => &it.syntax,
2226 Pat::RecordPat(it) => &it.syntax,
2227 Pat::TupleStructPat(it) => &it.syntax,
2228 Pat::TuplePat(it) => &it.syntax,
2229 Pat::SlicePat(it) => &it.syntax,
2230 Pat::RangePat(it) => &it.syntax,
2231 Pat::LiteralPat(it) => &it.syntax,
2236 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2238 pub(crate) syntax: SyntaxNode,
2240 impl AstNode for Path {
2241 fn can_cast(kind: SyntaxKind) -> bool {
2247 fn cast(syntax: SyntaxNode) -> Option<Self> {
2248 if Self::can_cast(syntax.kind()) {
2249 Some(Self { syntax })
2254 fn syntax(&self) -> &SyntaxNode {
2259 pub fn segment(&self) -> Option<PathSegment> {
2260 AstChildren::new(&self.syntax).next()
2262 pub fn qualifier(&self) -> Option<Path> {
2263 AstChildren::new(&self.syntax).next()
2266 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2267 pub struct PathExpr {
2268 pub(crate) syntax: SyntaxNode,
2270 impl AstNode for PathExpr {
2271 fn can_cast(kind: SyntaxKind) -> bool {
2277 fn cast(syntax: SyntaxNode) -> Option<Self> {
2278 if Self::can_cast(syntax.kind()) {
2279 Some(Self { syntax })
2284 fn syntax(&self) -> &SyntaxNode {
2289 pub fn path(&self) -> Option<Path> {
2290 AstChildren::new(&self.syntax).next()
2293 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2294 pub struct PathPat {
2295 pub(crate) syntax: SyntaxNode,
2297 impl AstNode for PathPat {
2298 fn can_cast(kind: SyntaxKind) -> bool {
2304 fn cast(syntax: SyntaxNode) -> Option<Self> {
2305 if Self::can_cast(syntax.kind()) {
2306 Some(Self { syntax })
2311 fn syntax(&self) -> &SyntaxNode {
2316 pub fn path(&self) -> Option<Path> {
2317 AstChildren::new(&self.syntax).next()
2320 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2321 pub struct PathSegment {
2322 pub(crate) syntax: SyntaxNode,
2324 impl AstNode for PathSegment {
2325 fn can_cast(kind: SyntaxKind) -> bool {
2327 PATH_SEGMENT => true,
2331 fn cast(syntax: SyntaxNode) -> Option<Self> {
2332 if Self::can_cast(syntax.kind()) {
2333 Some(Self { syntax })
2338 fn syntax(&self) -> &SyntaxNode {
2343 pub fn name_ref(&self) -> Option<NameRef> {
2344 AstChildren::new(&self.syntax).next()
2346 pub fn type_arg_list(&self) -> Option<TypeArgList> {
2347 AstChildren::new(&self.syntax).next()
2349 pub fn param_list(&self) -> Option<ParamList> {
2350 AstChildren::new(&self.syntax).next()
2352 pub fn ret_type(&self) -> Option<RetType> {
2353 AstChildren::new(&self.syntax).next()
2356 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2357 pub struct PathType {
2358 pub(crate) syntax: SyntaxNode,
2360 impl AstNode for PathType {
2361 fn can_cast(kind: SyntaxKind) -> bool {
2367 fn cast(syntax: SyntaxNode) -> Option<Self> {
2368 if Self::can_cast(syntax.kind()) {
2369 Some(Self { syntax })
2374 fn syntax(&self) -> &SyntaxNode {
2379 pub fn path(&self) -> Option<Path> {
2380 AstChildren::new(&self.syntax).next()
2383 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2384 pub struct PlaceholderPat {
2385 pub(crate) syntax: SyntaxNode,
2387 impl AstNode for PlaceholderPat {
2388 fn can_cast(kind: SyntaxKind) -> bool {
2390 PLACEHOLDER_PAT => true,
2394 fn cast(syntax: SyntaxNode) -> Option<Self> {
2395 if Self::can_cast(syntax.kind()) {
2396 Some(Self { syntax })
2401 fn syntax(&self) -> &SyntaxNode {
2405 impl PlaceholderPat {}
2406 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2407 pub struct PlaceholderType {
2408 pub(crate) syntax: SyntaxNode,
2410 impl AstNode for PlaceholderType {
2411 fn can_cast(kind: SyntaxKind) -> bool {
2413 PLACEHOLDER_TYPE => true,
2417 fn cast(syntax: SyntaxNode) -> Option<Self> {
2418 if Self::can_cast(syntax.kind()) {
2419 Some(Self { syntax })
2424 fn syntax(&self) -> &SyntaxNode {
2428 impl PlaceholderType {}
2429 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2430 pub struct PointerType {
2431 pub(crate) syntax: SyntaxNode,
2433 impl AstNode for PointerType {
2434 fn can_cast(kind: SyntaxKind) -> bool {
2436 POINTER_TYPE => true,
2440 fn cast(syntax: SyntaxNode) -> Option<Self> {
2441 if Self::can_cast(syntax.kind()) {
2442 Some(Self { syntax })
2447 fn syntax(&self) -> &SyntaxNode {
2452 pub fn type_ref(&self) -> Option<TypeRef> {
2453 AstChildren::new(&self.syntax).next()
2456 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2457 pub struct PrefixExpr {
2458 pub(crate) syntax: SyntaxNode,
2460 impl AstNode for PrefixExpr {
2461 fn can_cast(kind: SyntaxKind) -> bool {
2463 PREFIX_EXPR => true,
2467 fn cast(syntax: SyntaxNode) -> Option<Self> {
2468 if Self::can_cast(syntax.kind()) {
2469 Some(Self { syntax })
2474 fn syntax(&self) -> &SyntaxNode {
2479 pub fn expr(&self) -> Option<Expr> {
2480 AstChildren::new(&self.syntax).next()
2483 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2484 pub struct RangeExpr {
2485 pub(crate) syntax: SyntaxNode,
2487 impl AstNode for RangeExpr {
2488 fn can_cast(kind: SyntaxKind) -> bool {
2494 fn cast(syntax: SyntaxNode) -> Option<Self> {
2495 if Self::can_cast(syntax.kind()) {
2496 Some(Self { syntax })
2501 fn syntax(&self) -> &SyntaxNode {
2506 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2507 pub struct RangePat {
2508 pub(crate) syntax: SyntaxNode,
2510 impl AstNode for RangePat {
2511 fn can_cast(kind: SyntaxKind) -> bool {
2517 fn cast(syntax: SyntaxNode) -> Option<Self> {
2518 if Self::can_cast(syntax.kind()) {
2519 Some(Self { syntax })
2524 fn syntax(&self) -> &SyntaxNode {
2529 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2530 pub struct RecordField {
2531 pub(crate) syntax: SyntaxNode,
2533 impl AstNode for RecordField {
2534 fn can_cast(kind: SyntaxKind) -> bool {
2536 RECORD_FIELD => true,
2540 fn cast(syntax: SyntaxNode) -> Option<Self> {
2541 if Self::can_cast(syntax.kind()) {
2542 Some(Self { syntax })
2547 fn syntax(&self) -> &SyntaxNode {
2552 pub fn name_ref(&self) -> Option<NameRef> {
2553 AstChildren::new(&self.syntax).next()
2555 pub fn expr(&self) -> Option<Expr> {
2556 AstChildren::new(&self.syntax).next()
2559 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2560 pub struct RecordFieldDef {
2561 pub(crate) syntax: SyntaxNode,
2563 impl AstNode for RecordFieldDef {
2564 fn can_cast(kind: SyntaxKind) -> bool {
2566 RECORD_FIELD_DEF => true,
2570 fn cast(syntax: SyntaxNode) -> Option<Self> {
2571 if Self::can_cast(syntax.kind()) {
2572 Some(Self { syntax })
2577 fn syntax(&self) -> &SyntaxNode {
2581 impl ast::VisibilityOwner for RecordFieldDef {}
2582 impl ast::NameOwner for RecordFieldDef {}
2583 impl ast::AttrsOwner for RecordFieldDef {}
2584 impl ast::DocCommentsOwner for RecordFieldDef {}
2585 impl ast::TypeAscriptionOwner for RecordFieldDef {}
2586 impl RecordFieldDef {}
2587 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2588 pub struct RecordFieldDefList {
2589 pub(crate) syntax: SyntaxNode,
2591 impl AstNode for RecordFieldDefList {
2592 fn can_cast(kind: SyntaxKind) -> bool {
2594 RECORD_FIELD_DEF_LIST => true,
2598 fn cast(syntax: SyntaxNode) -> Option<Self> {
2599 if Self::can_cast(syntax.kind()) {
2600 Some(Self { syntax })
2605 fn syntax(&self) -> &SyntaxNode {
2609 impl RecordFieldDefList {
2610 pub fn fields(&self) -> AstChildren<RecordFieldDef> {
2611 AstChildren::new(&self.syntax)
2614 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2615 pub struct RecordFieldList {
2616 pub(crate) syntax: SyntaxNode,
2618 impl AstNode for RecordFieldList {
2619 fn can_cast(kind: SyntaxKind) -> bool {
2621 RECORD_FIELD_LIST => true,
2625 fn cast(syntax: SyntaxNode) -> Option<Self> {
2626 if Self::can_cast(syntax.kind()) {
2627 Some(Self { syntax })
2632 fn syntax(&self) -> &SyntaxNode {
2636 impl RecordFieldList {
2637 pub fn fields(&self) -> AstChildren<RecordField> {
2638 AstChildren::new(&self.syntax)
2640 pub fn spread(&self) -> Option<Expr> {
2641 AstChildren::new(&self.syntax).next()
2644 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2645 pub struct RecordFieldPat {
2646 pub(crate) syntax: SyntaxNode,
2648 impl AstNode for RecordFieldPat {
2649 fn can_cast(kind: SyntaxKind) -> bool {
2651 RECORD_FIELD_PAT => true,
2655 fn cast(syntax: SyntaxNode) -> Option<Self> {
2656 if Self::can_cast(syntax.kind()) {
2657 Some(Self { syntax })
2662 fn syntax(&self) -> &SyntaxNode {
2666 impl ast::NameOwner for RecordFieldPat {}
2667 impl RecordFieldPat {
2668 pub fn pat(&self) -> Option<Pat> {
2669 AstChildren::new(&self.syntax).next()
2672 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2673 pub struct RecordFieldPatList {
2674 pub(crate) syntax: SyntaxNode,
2676 impl AstNode for RecordFieldPatList {
2677 fn can_cast(kind: SyntaxKind) -> bool {
2679 RECORD_FIELD_PAT_LIST => true,
2683 fn cast(syntax: SyntaxNode) -> Option<Self> {
2684 if Self::can_cast(syntax.kind()) {
2685 Some(Self { syntax })
2690 fn syntax(&self) -> &SyntaxNode {
2694 impl RecordFieldPatList {
2695 pub fn record_field_pats(&self) -> AstChildren<RecordFieldPat> {
2696 AstChildren::new(&self.syntax)
2698 pub fn bind_pats(&self) -> AstChildren<BindPat> {
2699 AstChildren::new(&self.syntax)
2702 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2703 pub struct RecordLit {
2704 pub(crate) syntax: SyntaxNode,
2706 impl AstNode for RecordLit {
2707 fn can_cast(kind: SyntaxKind) -> bool {
2713 fn cast(syntax: SyntaxNode) -> Option<Self> {
2714 if Self::can_cast(syntax.kind()) {
2715 Some(Self { syntax })
2720 fn syntax(&self) -> &SyntaxNode {
2725 pub fn path(&self) -> Option<Path> {
2726 AstChildren::new(&self.syntax).next()
2728 pub fn record_field_list(&self) -> Option<RecordFieldList> {
2729 AstChildren::new(&self.syntax).next()
2732 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2733 pub struct RecordPat {
2734 pub(crate) syntax: SyntaxNode,
2736 impl AstNode for RecordPat {
2737 fn can_cast(kind: SyntaxKind) -> bool {
2743 fn cast(syntax: SyntaxNode) -> Option<Self> {
2744 if Self::can_cast(syntax.kind()) {
2745 Some(Self { syntax })
2750 fn syntax(&self) -> &SyntaxNode {
2755 pub fn record_field_pat_list(&self) -> Option<RecordFieldPatList> {
2756 AstChildren::new(&self.syntax).next()
2758 pub fn path(&self) -> Option<Path> {
2759 AstChildren::new(&self.syntax).next()
2762 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2763 pub struct RefExpr {
2764 pub(crate) syntax: SyntaxNode,
2766 impl AstNode for RefExpr {
2767 fn can_cast(kind: SyntaxKind) -> bool {
2773 fn cast(syntax: SyntaxNode) -> Option<Self> {
2774 if Self::can_cast(syntax.kind()) {
2775 Some(Self { syntax })
2780 fn syntax(&self) -> &SyntaxNode {
2785 pub fn expr(&self) -> Option<Expr> {
2786 AstChildren::new(&self.syntax).next()
2789 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2791 pub(crate) syntax: SyntaxNode,
2793 impl AstNode for RefPat {
2794 fn can_cast(kind: SyntaxKind) -> bool {
2800 fn cast(syntax: SyntaxNode) -> Option<Self> {
2801 if Self::can_cast(syntax.kind()) {
2802 Some(Self { syntax })
2807 fn syntax(&self) -> &SyntaxNode {
2812 pub fn pat(&self) -> Option<Pat> {
2813 AstChildren::new(&self.syntax).next()
2816 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2817 pub struct ReferenceType {
2818 pub(crate) syntax: SyntaxNode,
2820 impl AstNode for ReferenceType {
2821 fn can_cast(kind: SyntaxKind) -> bool {
2823 REFERENCE_TYPE => true,
2827 fn cast(syntax: SyntaxNode) -> Option<Self> {
2828 if Self::can_cast(syntax.kind()) {
2829 Some(Self { syntax })
2834 fn syntax(&self) -> &SyntaxNode {
2838 impl ReferenceType {
2839 pub fn type_ref(&self) -> Option<TypeRef> {
2840 AstChildren::new(&self.syntax).next()
2843 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2844 pub struct RetType {
2845 pub(crate) syntax: SyntaxNode,
2847 impl AstNode for RetType {
2848 fn can_cast(kind: SyntaxKind) -> bool {
2854 fn cast(syntax: SyntaxNode) -> Option<Self> {
2855 if Self::can_cast(syntax.kind()) {
2856 Some(Self { syntax })
2861 fn syntax(&self) -> &SyntaxNode {
2866 pub fn type_ref(&self) -> Option<TypeRef> {
2867 AstChildren::new(&self.syntax).next()
2870 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2871 pub struct ReturnExpr {
2872 pub(crate) syntax: SyntaxNode,
2874 impl AstNode for ReturnExpr {
2875 fn can_cast(kind: SyntaxKind) -> bool {
2877 RETURN_EXPR => true,
2881 fn cast(syntax: SyntaxNode) -> Option<Self> {
2882 if Self::can_cast(syntax.kind()) {
2883 Some(Self { syntax })
2888 fn syntax(&self) -> &SyntaxNode {
2893 pub fn expr(&self) -> Option<Expr> {
2894 AstChildren::new(&self.syntax).next()
2897 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2898 pub struct SelfParam {
2899 pub(crate) syntax: SyntaxNode,
2901 impl AstNode for SelfParam {
2902 fn can_cast(kind: SyntaxKind) -> bool {
2908 fn cast(syntax: SyntaxNode) -> Option<Self> {
2909 if Self::can_cast(syntax.kind()) {
2910 Some(Self { syntax })
2915 fn syntax(&self) -> &SyntaxNode {
2919 impl ast::TypeAscriptionOwner for SelfParam {}
2920 impl ast::AttrsOwner for SelfParam {}
2922 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2923 pub struct SlicePat {
2924 pub(crate) syntax: SyntaxNode,
2926 impl AstNode for SlicePat {
2927 fn can_cast(kind: SyntaxKind) -> bool {
2933 fn cast(syntax: SyntaxNode) -> Option<Self> {
2934 if Self::can_cast(syntax.kind()) {
2935 Some(Self { syntax })
2940 fn syntax(&self) -> &SyntaxNode {
2945 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2946 pub struct SliceType {
2947 pub(crate) syntax: SyntaxNode,
2949 impl AstNode for SliceType {
2950 fn can_cast(kind: SyntaxKind) -> bool {
2956 fn cast(syntax: SyntaxNode) -> Option<Self> {
2957 if Self::can_cast(syntax.kind()) {
2958 Some(Self { syntax })
2963 fn syntax(&self) -> &SyntaxNode {
2968 pub fn type_ref(&self) -> Option<TypeRef> {
2969 AstChildren::new(&self.syntax).next()
2972 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2973 pub struct SourceFile {
2974 pub(crate) syntax: SyntaxNode,
2976 impl AstNode for SourceFile {
2977 fn can_cast(kind: SyntaxKind) -> bool {
2979 SOURCE_FILE => true,
2983 fn cast(syntax: SyntaxNode) -> Option<Self> {
2984 if Self::can_cast(syntax.kind()) {
2985 Some(Self { syntax })
2990 fn syntax(&self) -> &SyntaxNode {
2994 impl ast::ModuleItemOwner for SourceFile {}
2995 impl ast::FnDefOwner for SourceFile {}
2997 pub fn modules(&self) -> AstChildren<Module> {
2998 AstChildren::new(&self.syntax)
3001 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3002 pub struct StaticDef {
3003 pub(crate) syntax: SyntaxNode,
3005 impl AstNode for StaticDef {
3006 fn can_cast(kind: SyntaxKind) -> bool {
3012 fn cast(syntax: SyntaxNode) -> Option<Self> {
3013 if Self::can_cast(syntax.kind()) {
3014 Some(Self { syntax })
3019 fn syntax(&self) -> &SyntaxNode {
3023 impl ast::VisibilityOwner for StaticDef {}
3024 impl ast::NameOwner for StaticDef {}
3025 impl ast::TypeParamsOwner for StaticDef {}
3026 impl ast::AttrsOwner for StaticDef {}
3027 impl ast::DocCommentsOwner for StaticDef {}
3028 impl ast::TypeAscriptionOwner for StaticDef {}
3030 pub fn body(&self) -> Option<Expr> {
3031 AstChildren::new(&self.syntax).next()
3034 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3039 impl From<ExprStmt> for Stmt {
3040 fn from(node: ExprStmt) -> Stmt {
3041 Stmt::ExprStmt(node)
3044 impl From<LetStmt> for Stmt {
3045 fn from(node: LetStmt) -> Stmt {
3049 impl AstNode for Stmt {
3050 fn can_cast(kind: SyntaxKind) -> bool {
3052 EXPR_STMT | LET_STMT => true,
3056 fn cast(syntax: SyntaxNode) -> Option<Self> {
3057 let res = match syntax.kind() {
3058 EXPR_STMT => Stmt::ExprStmt(ExprStmt { syntax }),
3059 LET_STMT => Stmt::LetStmt(LetStmt { syntax }),
3064 fn syntax(&self) -> &SyntaxNode {
3066 Stmt::ExprStmt(it) => &it.syntax,
3067 Stmt::LetStmt(it) => &it.syntax,
3072 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3073 pub struct StructDef {
3074 pub(crate) syntax: SyntaxNode,
3076 impl AstNode for StructDef {
3077 fn can_cast(kind: SyntaxKind) -> bool {
3083 fn cast(syntax: SyntaxNode) -> Option<Self> {
3084 if Self::can_cast(syntax.kind()) {
3085 Some(Self { syntax })
3090 fn syntax(&self) -> &SyntaxNode {
3094 impl ast::VisibilityOwner for StructDef {}
3095 impl ast::NameOwner for StructDef {}
3096 impl ast::TypeParamsOwner for StructDef {}
3097 impl ast::AttrsOwner for StructDef {}
3098 impl ast::DocCommentsOwner for StructDef {}
3100 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3101 pub struct TokenTree {
3102 pub(crate) syntax: SyntaxNode,
3104 impl AstNode for TokenTree {
3105 fn can_cast(kind: SyntaxKind) -> bool {
3111 fn cast(syntax: SyntaxNode) -> Option<Self> {
3112 if Self::can_cast(syntax.kind()) {
3113 Some(Self { syntax })
3118 fn syntax(&self) -> &SyntaxNode {
3123 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3124 pub struct TraitDef {
3125 pub(crate) syntax: SyntaxNode,
3127 impl AstNode for TraitDef {
3128 fn can_cast(kind: SyntaxKind) -> bool {
3134 fn cast(syntax: SyntaxNode) -> Option<Self> {
3135 if Self::can_cast(syntax.kind()) {
3136 Some(Self { syntax })
3141 fn syntax(&self) -> &SyntaxNode {
3145 impl ast::VisibilityOwner for TraitDef {}
3146 impl ast::NameOwner for TraitDef {}
3147 impl ast::AttrsOwner for TraitDef {}
3148 impl ast::DocCommentsOwner for TraitDef {}
3149 impl ast::TypeParamsOwner for TraitDef {}
3150 impl ast::TypeBoundsOwner for TraitDef {}
3152 pub fn item_list(&self) -> Option<ItemList> {
3153 AstChildren::new(&self.syntax).next()
3156 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3157 pub struct TryBlockExpr {
3158 pub(crate) syntax: SyntaxNode,
3160 impl AstNode for TryBlockExpr {
3161 fn can_cast(kind: SyntaxKind) -> bool {
3163 TRY_BLOCK_EXPR => true,
3167 fn cast(syntax: SyntaxNode) -> Option<Self> {
3168 if Self::can_cast(syntax.kind()) {
3169 Some(Self { syntax })
3174 fn syntax(&self) -> &SyntaxNode {
3179 pub fn body(&self) -> Option<BlockExpr> {
3180 AstChildren::new(&self.syntax).next()
3183 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3184 pub struct TryExpr {
3185 pub(crate) syntax: SyntaxNode,
3187 impl AstNode for TryExpr {
3188 fn can_cast(kind: SyntaxKind) -> bool {
3194 fn cast(syntax: SyntaxNode) -> Option<Self> {
3195 if Self::can_cast(syntax.kind()) {
3196 Some(Self { syntax })
3201 fn syntax(&self) -> &SyntaxNode {
3206 pub fn expr(&self) -> Option<Expr> {
3207 AstChildren::new(&self.syntax).next()
3210 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3211 pub struct TupleExpr {
3212 pub(crate) syntax: SyntaxNode,
3214 impl AstNode for TupleExpr {
3215 fn can_cast(kind: SyntaxKind) -> bool {
3221 fn cast(syntax: SyntaxNode) -> Option<Self> {
3222 if Self::can_cast(syntax.kind()) {
3223 Some(Self { syntax })
3228 fn syntax(&self) -> &SyntaxNode {
3233 pub fn exprs(&self) -> AstChildren<Expr> {
3234 AstChildren::new(&self.syntax)
3237 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3238 pub struct TupleFieldDef {
3239 pub(crate) syntax: SyntaxNode,
3241 impl AstNode for TupleFieldDef {
3242 fn can_cast(kind: SyntaxKind) -> bool {
3244 TUPLE_FIELD_DEF => true,
3248 fn cast(syntax: SyntaxNode) -> Option<Self> {
3249 if Self::can_cast(syntax.kind()) {
3250 Some(Self { syntax })
3255 fn syntax(&self) -> &SyntaxNode {
3259 impl ast::VisibilityOwner for TupleFieldDef {}
3260 impl ast::AttrsOwner for TupleFieldDef {}
3261 impl TupleFieldDef {
3262 pub fn type_ref(&self) -> Option<TypeRef> {
3263 AstChildren::new(&self.syntax).next()
3266 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3267 pub struct TupleFieldDefList {
3268 pub(crate) syntax: SyntaxNode,
3270 impl AstNode for TupleFieldDefList {
3271 fn can_cast(kind: SyntaxKind) -> bool {
3273 TUPLE_FIELD_DEF_LIST => true,
3277 fn cast(syntax: SyntaxNode) -> Option<Self> {
3278 if Self::can_cast(syntax.kind()) {
3279 Some(Self { syntax })
3284 fn syntax(&self) -> &SyntaxNode {
3288 impl TupleFieldDefList {
3289 pub fn fields(&self) -> AstChildren<TupleFieldDef> {
3290 AstChildren::new(&self.syntax)
3293 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3294 pub struct TuplePat {
3295 pub(crate) syntax: SyntaxNode,
3297 impl AstNode for TuplePat {
3298 fn can_cast(kind: SyntaxKind) -> bool {
3304 fn cast(syntax: SyntaxNode) -> Option<Self> {
3305 if Self::can_cast(syntax.kind()) {
3306 Some(Self { syntax })
3311 fn syntax(&self) -> &SyntaxNode {
3316 pub fn args(&self) -> AstChildren<Pat> {
3317 AstChildren::new(&self.syntax)
3320 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3321 pub struct TupleStructPat {
3322 pub(crate) syntax: SyntaxNode,
3324 impl AstNode for TupleStructPat {
3325 fn can_cast(kind: SyntaxKind) -> bool {
3327 TUPLE_STRUCT_PAT => true,
3331 fn cast(syntax: SyntaxNode) -> Option<Self> {
3332 if Self::can_cast(syntax.kind()) {
3333 Some(Self { syntax })
3338 fn syntax(&self) -> &SyntaxNode {
3342 impl TupleStructPat {
3343 pub fn args(&self) -> AstChildren<Pat> {
3344 AstChildren::new(&self.syntax)
3346 pub fn path(&self) -> Option<Path> {
3347 AstChildren::new(&self.syntax).next()
3350 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3351 pub struct TupleType {
3352 pub(crate) syntax: SyntaxNode,
3354 impl AstNode for TupleType {
3355 fn can_cast(kind: SyntaxKind) -> bool {
3361 fn cast(syntax: SyntaxNode) -> Option<Self> {
3362 if Self::can_cast(syntax.kind()) {
3363 Some(Self { syntax })
3368 fn syntax(&self) -> &SyntaxNode {
3373 pub fn fields(&self) -> AstChildren<TypeRef> {
3374 AstChildren::new(&self.syntax)
3377 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3378 pub struct TypeAliasDef {
3379 pub(crate) syntax: SyntaxNode,
3381 impl AstNode for TypeAliasDef {
3382 fn can_cast(kind: SyntaxKind) -> bool {
3384 TYPE_ALIAS_DEF => true,
3388 fn cast(syntax: SyntaxNode) -> Option<Self> {
3389 if Self::can_cast(syntax.kind()) {
3390 Some(Self { syntax })
3395 fn syntax(&self) -> &SyntaxNode {
3399 impl ast::VisibilityOwner for TypeAliasDef {}
3400 impl ast::NameOwner for TypeAliasDef {}
3401 impl ast::TypeParamsOwner for TypeAliasDef {}
3402 impl ast::AttrsOwner for TypeAliasDef {}
3403 impl ast::DocCommentsOwner for TypeAliasDef {}
3404 impl ast::TypeBoundsOwner for TypeAliasDef {}
3406 pub fn type_ref(&self) -> Option<TypeRef> {
3407 AstChildren::new(&self.syntax).next()
3410 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3411 pub struct TypeArg {
3412 pub(crate) syntax: SyntaxNode,
3414 impl AstNode for TypeArg {
3415 fn can_cast(kind: SyntaxKind) -> bool {
3421 fn cast(syntax: SyntaxNode) -> Option<Self> {
3422 if Self::can_cast(syntax.kind()) {
3423 Some(Self { syntax })
3428 fn syntax(&self) -> &SyntaxNode {
3433 pub fn type_ref(&self) -> Option<TypeRef> {
3434 AstChildren::new(&self.syntax).next()
3437 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3438 pub struct TypeArgList {
3439 pub(crate) syntax: SyntaxNode,
3441 impl AstNode for TypeArgList {
3442 fn can_cast(kind: SyntaxKind) -> bool {
3444 TYPE_ARG_LIST => true,
3448 fn cast(syntax: SyntaxNode) -> Option<Self> {
3449 if Self::can_cast(syntax.kind()) {
3450 Some(Self { syntax })
3455 fn syntax(&self) -> &SyntaxNode {
3460 pub fn type_args(&self) -> AstChildren<TypeArg> {
3461 AstChildren::new(&self.syntax)
3463 pub fn lifetime_args(&self) -> AstChildren<LifetimeArg> {
3464 AstChildren::new(&self.syntax)
3466 pub fn assoc_type_args(&self) -> AstChildren<AssocTypeArg> {
3467 AstChildren::new(&self.syntax)
3470 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3471 pub struct TypeBound {
3472 pub(crate) syntax: SyntaxNode,
3474 impl AstNode for TypeBound {
3475 fn can_cast(kind: SyntaxKind) -> bool {
3481 fn cast(syntax: SyntaxNode) -> Option<Self> {
3482 if Self::can_cast(syntax.kind()) {
3483 Some(Self { syntax })
3488 fn syntax(&self) -> &SyntaxNode {
3493 pub fn type_ref(&self) -> Option<TypeRef> {
3494 AstChildren::new(&self.syntax).next()
3497 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3498 pub struct TypeBoundList {
3499 pub(crate) syntax: SyntaxNode,
3501 impl AstNode for TypeBoundList {
3502 fn can_cast(kind: SyntaxKind) -> bool {
3504 TYPE_BOUND_LIST => true,
3508 fn cast(syntax: SyntaxNode) -> Option<Self> {
3509 if Self::can_cast(syntax.kind()) {
3510 Some(Self { syntax })
3515 fn syntax(&self) -> &SyntaxNode {
3519 impl TypeBoundList {
3520 pub fn bounds(&self) -> AstChildren<TypeBound> {
3521 AstChildren::new(&self.syntax)
3524 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3525 pub struct TypeParam {
3526 pub(crate) syntax: SyntaxNode,
3528 impl AstNode for TypeParam {
3529 fn can_cast(kind: SyntaxKind) -> bool {
3535 fn cast(syntax: SyntaxNode) -> Option<Self> {
3536 if Self::can_cast(syntax.kind()) {
3537 Some(Self { syntax })
3542 fn syntax(&self) -> &SyntaxNode {
3546 impl ast::NameOwner for TypeParam {}
3547 impl ast::AttrsOwner for TypeParam {}
3548 impl ast::TypeBoundsOwner for TypeParam {}
3549 impl ast::DefaultTypeParamOwner for TypeParam {}
3551 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3552 pub struct TypeParamList {
3553 pub(crate) syntax: SyntaxNode,
3555 impl AstNode for TypeParamList {
3556 fn can_cast(kind: SyntaxKind) -> bool {
3558 TYPE_PARAM_LIST => true,
3562 fn cast(syntax: SyntaxNode) -> Option<Self> {
3563 if Self::can_cast(syntax.kind()) {
3564 Some(Self { syntax })
3569 fn syntax(&self) -> &SyntaxNode {
3573 impl TypeParamList {
3574 pub fn type_params(&self) -> AstChildren<TypeParam> {
3575 AstChildren::new(&self.syntax)
3577 pub fn lifetime_params(&self) -> AstChildren<LifetimeParam> {
3578 AstChildren::new(&self.syntax)
3581 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3583 ParenType(ParenType),
3584 TupleType(TupleType),
3585 NeverType(NeverType),
3587 PointerType(PointerType),
3588 ArrayType(ArrayType),
3589 SliceType(SliceType),
3590 ReferenceType(ReferenceType),
3591 PlaceholderType(PlaceholderType),
3592 FnPointerType(FnPointerType),
3594 ImplTraitType(ImplTraitType),
3595 DynTraitType(DynTraitType),
3597 impl From<ParenType> for TypeRef {
3598 fn from(node: ParenType) -> TypeRef {
3599 TypeRef::ParenType(node)
3602 impl From<TupleType> for TypeRef {
3603 fn from(node: TupleType) -> TypeRef {
3604 TypeRef::TupleType(node)
3607 impl From<NeverType> for TypeRef {
3608 fn from(node: NeverType) -> TypeRef {
3609 TypeRef::NeverType(node)
3612 impl From<PathType> for TypeRef {
3613 fn from(node: PathType) -> TypeRef {
3614 TypeRef::PathType(node)
3617 impl From<PointerType> for TypeRef {
3618 fn from(node: PointerType) -> TypeRef {
3619 TypeRef::PointerType(node)
3622 impl From<ArrayType> for TypeRef {
3623 fn from(node: ArrayType) -> TypeRef {
3624 TypeRef::ArrayType(node)
3627 impl From<SliceType> for TypeRef {
3628 fn from(node: SliceType) -> TypeRef {
3629 TypeRef::SliceType(node)
3632 impl From<ReferenceType> for TypeRef {
3633 fn from(node: ReferenceType) -> TypeRef {
3634 TypeRef::ReferenceType(node)
3637 impl From<PlaceholderType> for TypeRef {
3638 fn from(node: PlaceholderType) -> TypeRef {
3639 TypeRef::PlaceholderType(node)
3642 impl From<FnPointerType> for TypeRef {
3643 fn from(node: FnPointerType) -> TypeRef {
3644 TypeRef::FnPointerType(node)
3647 impl From<ForType> for TypeRef {
3648 fn from(node: ForType) -> TypeRef {
3649 TypeRef::ForType(node)
3652 impl From<ImplTraitType> for TypeRef {
3653 fn from(node: ImplTraitType) -> TypeRef {
3654 TypeRef::ImplTraitType(node)
3657 impl From<DynTraitType> for TypeRef {
3658 fn from(node: DynTraitType) -> TypeRef {
3659 TypeRef::DynTraitType(node)
3662 impl AstNode for TypeRef {
3663 fn can_cast(kind: SyntaxKind) -> bool {
3665 PAREN_TYPE | TUPLE_TYPE | NEVER_TYPE | PATH_TYPE | POINTER_TYPE | ARRAY_TYPE
3666 | SLICE_TYPE | REFERENCE_TYPE | PLACEHOLDER_TYPE | FN_POINTER_TYPE | FOR_TYPE
3667 | IMPL_TRAIT_TYPE | DYN_TRAIT_TYPE => true,
3671 fn cast(syntax: SyntaxNode) -> Option<Self> {
3672 let res = match syntax.kind() {
3673 PAREN_TYPE => TypeRef::ParenType(ParenType { syntax }),
3674 TUPLE_TYPE => TypeRef::TupleType(TupleType { syntax }),
3675 NEVER_TYPE => TypeRef::NeverType(NeverType { syntax }),
3676 PATH_TYPE => TypeRef::PathType(PathType { syntax }),
3677 POINTER_TYPE => TypeRef::PointerType(PointerType { syntax }),
3678 ARRAY_TYPE => TypeRef::ArrayType(ArrayType { syntax }),
3679 SLICE_TYPE => TypeRef::SliceType(SliceType { syntax }),
3680 REFERENCE_TYPE => TypeRef::ReferenceType(ReferenceType { syntax }),
3681 PLACEHOLDER_TYPE => TypeRef::PlaceholderType(PlaceholderType { syntax }),
3682 FN_POINTER_TYPE => TypeRef::FnPointerType(FnPointerType { syntax }),
3683 FOR_TYPE => TypeRef::ForType(ForType { syntax }),
3684 IMPL_TRAIT_TYPE => TypeRef::ImplTraitType(ImplTraitType { syntax }),
3685 DYN_TRAIT_TYPE => TypeRef::DynTraitType(DynTraitType { syntax }),
3690 fn syntax(&self) -> &SyntaxNode {
3692 TypeRef::ParenType(it) => &it.syntax,
3693 TypeRef::TupleType(it) => &it.syntax,
3694 TypeRef::NeverType(it) => &it.syntax,
3695 TypeRef::PathType(it) => &it.syntax,
3696 TypeRef::PointerType(it) => &it.syntax,
3697 TypeRef::ArrayType(it) => &it.syntax,
3698 TypeRef::SliceType(it) => &it.syntax,
3699 TypeRef::ReferenceType(it) => &it.syntax,
3700 TypeRef::PlaceholderType(it) => &it.syntax,
3701 TypeRef::FnPointerType(it) => &it.syntax,
3702 TypeRef::ForType(it) => &it.syntax,
3703 TypeRef::ImplTraitType(it) => &it.syntax,
3704 TypeRef::DynTraitType(it) => &it.syntax,
3709 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3710 pub struct UseItem {
3711 pub(crate) syntax: SyntaxNode,
3713 impl AstNode for UseItem {
3714 fn can_cast(kind: SyntaxKind) -> bool {
3720 fn cast(syntax: SyntaxNode) -> Option<Self> {
3721 if Self::can_cast(syntax.kind()) {
3722 Some(Self { syntax })
3727 fn syntax(&self) -> &SyntaxNode {
3731 impl ast::AttrsOwner for UseItem {}
3733 pub fn use_tree(&self) -> Option<UseTree> {
3734 AstChildren::new(&self.syntax).next()
3737 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3738 pub struct UseTree {
3739 pub(crate) syntax: SyntaxNode,
3741 impl AstNode for UseTree {
3742 fn can_cast(kind: SyntaxKind) -> bool {
3748 fn cast(syntax: SyntaxNode) -> Option<Self> {
3749 if Self::can_cast(syntax.kind()) {
3750 Some(Self { syntax })
3755 fn syntax(&self) -> &SyntaxNode {
3760 pub fn path(&self) -> Option<Path> {
3761 AstChildren::new(&self.syntax).next()
3763 pub fn use_tree_list(&self) -> Option<UseTreeList> {
3764 AstChildren::new(&self.syntax).next()
3766 pub fn alias(&self) -> Option<Alias> {
3767 AstChildren::new(&self.syntax).next()
3770 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3771 pub struct UseTreeList {
3772 pub(crate) syntax: SyntaxNode,
3774 impl AstNode for UseTreeList {
3775 fn can_cast(kind: SyntaxKind) -> bool {
3777 USE_TREE_LIST => true,
3781 fn cast(syntax: SyntaxNode) -> Option<Self> {
3782 if Self::can_cast(syntax.kind()) {
3783 Some(Self { syntax })
3788 fn syntax(&self) -> &SyntaxNode {
3793 pub fn use_trees(&self) -> AstChildren<UseTree> {
3794 AstChildren::new(&self.syntax)
3797 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3798 pub struct Visibility {
3799 pub(crate) syntax: SyntaxNode,
3801 impl AstNode for Visibility {
3802 fn can_cast(kind: SyntaxKind) -> bool {
3808 fn cast(syntax: SyntaxNode) -> Option<Self> {
3809 if Self::can_cast(syntax.kind()) {
3810 Some(Self { syntax })
3815 fn syntax(&self) -> &SyntaxNode {
3820 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3821 pub struct WhereClause {
3822 pub(crate) syntax: SyntaxNode,
3824 impl AstNode for WhereClause {
3825 fn can_cast(kind: SyntaxKind) -> bool {
3827 WHERE_CLAUSE => true,
3831 fn cast(syntax: SyntaxNode) -> Option<Self> {
3832 if Self::can_cast(syntax.kind()) {
3833 Some(Self { syntax })
3838 fn syntax(&self) -> &SyntaxNode {
3843 pub fn predicates(&self) -> AstChildren<WherePred> {
3844 AstChildren::new(&self.syntax)
3847 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3848 pub struct WherePred {
3849 pub(crate) syntax: SyntaxNode,
3851 impl AstNode for WherePred {
3852 fn can_cast(kind: SyntaxKind) -> bool {
3858 fn cast(syntax: SyntaxNode) -> Option<Self> {
3859 if Self::can_cast(syntax.kind()) {
3860 Some(Self { syntax })
3865 fn syntax(&self) -> &SyntaxNode {
3869 impl ast::TypeBoundsOwner for WherePred {}
3871 pub fn type_ref(&self) -> Option<TypeRef> {
3872 AstChildren::new(&self.syntax).next()
3875 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3876 pub struct WhileExpr {
3877 pub(crate) syntax: SyntaxNode,
3879 impl AstNode for WhileExpr {
3880 fn can_cast(kind: SyntaxKind) -> bool {
3886 fn cast(syntax: SyntaxNode) -> Option<Self> {
3887 if Self::can_cast(syntax.kind()) {
3888 Some(Self { syntax })
3893 fn syntax(&self) -> &SyntaxNode {
3897 impl ast::LoopBodyOwner for WhileExpr {}
3899 pub fn condition(&self) -> Option<Condition> {
3900 AstChildren::new(&self.syntax).next()