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)]
310 pub struct BreakExpr {
311 pub(crate) syntax: SyntaxNode,
313 impl AstNode for BreakExpr {
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)]
337 pub struct CallExpr {
338 pub(crate) syntax: SyntaxNode,
340 impl AstNode for CallExpr {
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 {
358 impl ast::ArgListOwner for CallExpr {}
360 pub fn expr(&self) -> Option<Expr> {
361 AstChildren::new(&self.syntax).next()
364 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
365 pub struct CastExpr {
366 pub(crate) syntax: SyntaxNode,
368 impl AstNode for CastExpr {
369 fn can_cast(kind: SyntaxKind) -> bool {
375 fn cast(syntax: SyntaxNode) -> Option<Self> {
376 if Self::can_cast(syntax.kind()) {
377 Some(Self { syntax })
382 fn syntax(&self) -> &SyntaxNode {
387 pub fn expr(&self) -> Option<Expr> {
388 AstChildren::new(&self.syntax).next()
390 pub fn type_ref(&self) -> Option<TypeRef> {
391 AstChildren::new(&self.syntax).next()
394 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
395 pub struct Condition {
396 pub(crate) syntax: SyntaxNode,
398 impl AstNode for Condition {
399 fn can_cast(kind: SyntaxKind) -> bool {
405 fn cast(syntax: SyntaxNode) -> Option<Self> {
406 if Self::can_cast(syntax.kind()) {
407 Some(Self { syntax })
412 fn syntax(&self) -> &SyntaxNode {
417 pub fn pat(&self) -> Option<Pat> {
418 AstChildren::new(&self.syntax).next()
420 pub fn expr(&self) -> Option<Expr> {
421 AstChildren::new(&self.syntax).next()
424 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
425 pub struct ConstDef {
426 pub(crate) syntax: SyntaxNode,
428 impl AstNode for ConstDef {
429 fn can_cast(kind: SyntaxKind) -> bool {
435 fn cast(syntax: SyntaxNode) -> Option<Self> {
436 if Self::can_cast(syntax.kind()) {
437 Some(Self { syntax })
442 fn syntax(&self) -> &SyntaxNode {
446 impl ast::VisibilityOwner for ConstDef {}
447 impl ast::NameOwner for ConstDef {}
448 impl ast::TypeParamsOwner for ConstDef {}
449 impl ast::AttrsOwner for ConstDef {}
450 impl ast::DocCommentsOwner for ConstDef {}
451 impl ast::TypeAscriptionOwner for ConstDef {}
453 pub fn body(&self) -> Option<Expr> {
454 AstChildren::new(&self.syntax).next()
457 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
458 pub struct ContinueExpr {
459 pub(crate) syntax: SyntaxNode,
461 impl AstNode for ContinueExpr {
462 fn can_cast(kind: SyntaxKind) -> bool {
464 CONTINUE_EXPR => true,
468 fn cast(syntax: SyntaxNode) -> Option<Self> {
469 if Self::can_cast(syntax.kind()) {
470 Some(Self { syntax })
475 fn syntax(&self) -> &SyntaxNode {
480 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
481 pub struct DynTraitType {
482 pub(crate) syntax: SyntaxNode,
484 impl AstNode for DynTraitType {
485 fn can_cast(kind: SyntaxKind) -> bool {
487 DYN_TRAIT_TYPE => true,
491 fn cast(syntax: SyntaxNode) -> Option<Self> {
492 if Self::can_cast(syntax.kind()) {
493 Some(Self { syntax })
498 fn syntax(&self) -> &SyntaxNode {
502 impl ast::TypeBoundsOwner for DynTraitType {}
504 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
506 pub(crate) syntax: SyntaxNode,
508 impl AstNode for EnumDef {
509 fn can_cast(kind: SyntaxKind) -> bool {
515 fn cast(syntax: SyntaxNode) -> Option<Self> {
516 if Self::can_cast(syntax.kind()) {
517 Some(Self { syntax })
522 fn syntax(&self) -> &SyntaxNode {
526 impl ast::VisibilityOwner for EnumDef {}
527 impl ast::NameOwner for EnumDef {}
528 impl ast::TypeParamsOwner for EnumDef {}
529 impl ast::AttrsOwner for EnumDef {}
530 impl ast::DocCommentsOwner for EnumDef {}
532 pub fn variant_list(&self) -> Option<EnumVariantList> {
533 AstChildren::new(&self.syntax).next()
536 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
537 pub struct EnumVariant {
538 pub(crate) syntax: SyntaxNode,
540 impl AstNode for EnumVariant {
541 fn can_cast(kind: SyntaxKind) -> bool {
543 ENUM_VARIANT => true,
547 fn cast(syntax: SyntaxNode) -> Option<Self> {
548 if Self::can_cast(syntax.kind()) {
549 Some(Self { syntax })
554 fn syntax(&self) -> &SyntaxNode {
558 impl ast::NameOwner for EnumVariant {}
559 impl ast::DocCommentsOwner for EnumVariant {}
560 impl ast::AttrsOwner for EnumVariant {}
562 pub fn expr(&self) -> Option<Expr> {
563 AstChildren::new(&self.syntax).next()
566 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
567 pub struct EnumVariantList {
568 pub(crate) syntax: SyntaxNode,
570 impl AstNode for EnumVariantList {
571 fn can_cast(kind: SyntaxKind) -> bool {
573 ENUM_VARIANT_LIST => true,
577 fn cast(syntax: SyntaxNode) -> Option<Self> {
578 if Self::can_cast(syntax.kind()) {
579 Some(Self { syntax })
584 fn syntax(&self) -> &SyntaxNode {
588 impl EnumVariantList {
589 pub fn variants(&self) -> AstChildren<EnumVariant> {
590 AstChildren::new(&self.syntax)
593 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
595 TupleExpr(TupleExpr),
596 ArrayExpr(ArrayExpr),
597 ParenExpr(ParenExpr),
599 LambdaExpr(LambdaExpr),
603 WhileExpr(WhileExpr),
604 ContinueExpr(ContinueExpr),
605 BreakExpr(BreakExpr),
607 BlockExpr(BlockExpr),
608 ReturnExpr(ReturnExpr),
609 MatchExpr(MatchExpr),
610 RecordLit(RecordLit),
612 IndexExpr(IndexExpr),
613 MethodCallExpr(MethodCallExpr),
614 FieldExpr(FieldExpr),
615 AwaitExpr(AwaitExpr),
617 TryBlockExpr(TryBlockExpr),
620 PrefixExpr(PrefixExpr),
621 RangeExpr(RangeExpr),
624 MacroCall(MacroCall),
626 impl From<TupleExpr> for Expr {
627 fn from(node: TupleExpr) -> Expr {
628 Expr::TupleExpr(node)
631 impl From<ArrayExpr> for Expr {
632 fn from(node: ArrayExpr) -> Expr {
633 Expr::ArrayExpr(node)
636 impl From<ParenExpr> for Expr {
637 fn from(node: ParenExpr) -> Expr {
638 Expr::ParenExpr(node)
641 impl From<PathExpr> for Expr {
642 fn from(node: PathExpr) -> Expr {
646 impl From<LambdaExpr> for Expr {
647 fn from(node: LambdaExpr) -> Expr {
648 Expr::LambdaExpr(node)
651 impl From<IfExpr> for Expr {
652 fn from(node: IfExpr) -> Expr {
656 impl From<LoopExpr> for Expr {
657 fn from(node: LoopExpr) -> Expr {
661 impl From<ForExpr> for Expr {
662 fn from(node: ForExpr) -> Expr {
666 impl From<WhileExpr> for Expr {
667 fn from(node: WhileExpr) -> Expr {
668 Expr::WhileExpr(node)
671 impl From<ContinueExpr> for Expr {
672 fn from(node: ContinueExpr) -> Expr {
673 Expr::ContinueExpr(node)
676 impl From<BreakExpr> for Expr {
677 fn from(node: BreakExpr) -> Expr {
678 Expr::BreakExpr(node)
681 impl From<Label> for Expr {
682 fn from(node: Label) -> Expr {
686 impl From<BlockExpr> for Expr {
687 fn from(node: BlockExpr) -> Expr {
688 Expr::BlockExpr(node)
691 impl From<ReturnExpr> for Expr {
692 fn from(node: ReturnExpr) -> Expr {
693 Expr::ReturnExpr(node)
696 impl From<MatchExpr> for Expr {
697 fn from(node: MatchExpr) -> Expr {
698 Expr::MatchExpr(node)
701 impl From<RecordLit> for Expr {
702 fn from(node: RecordLit) -> Expr {
703 Expr::RecordLit(node)
706 impl From<CallExpr> for Expr {
707 fn from(node: CallExpr) -> Expr {
711 impl From<IndexExpr> for Expr {
712 fn from(node: IndexExpr) -> Expr {
713 Expr::IndexExpr(node)
716 impl From<MethodCallExpr> for Expr {
717 fn from(node: MethodCallExpr) -> Expr {
718 Expr::MethodCallExpr(node)
721 impl From<FieldExpr> for Expr {
722 fn from(node: FieldExpr) -> Expr {
723 Expr::FieldExpr(node)
726 impl From<AwaitExpr> for Expr {
727 fn from(node: AwaitExpr) -> Expr {
728 Expr::AwaitExpr(node)
731 impl From<TryExpr> for Expr {
732 fn from(node: TryExpr) -> Expr {
736 impl From<TryBlockExpr> for Expr {
737 fn from(node: TryBlockExpr) -> Expr {
738 Expr::TryBlockExpr(node)
741 impl From<CastExpr> for Expr {
742 fn from(node: CastExpr) -> Expr {
746 impl From<RefExpr> for Expr {
747 fn from(node: RefExpr) -> Expr {
751 impl From<PrefixExpr> for Expr {
752 fn from(node: PrefixExpr) -> Expr {
753 Expr::PrefixExpr(node)
756 impl From<RangeExpr> for Expr {
757 fn from(node: RangeExpr) -> Expr {
758 Expr::RangeExpr(node)
761 impl From<BinExpr> for Expr {
762 fn from(node: BinExpr) -> Expr {
766 impl From<Literal> for Expr {
767 fn from(node: Literal) -> Expr {
771 impl From<MacroCall> for Expr {
772 fn from(node: MacroCall) -> Expr {
773 Expr::MacroCall(node)
776 impl AstNode for Expr {
777 fn can_cast(kind: SyntaxKind) -> bool {
779 TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR
780 | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL
781 | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | RECORD_LIT | CALL_EXPR | INDEX_EXPR
782 | METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | TRY_BLOCK_EXPR
783 | CAST_EXPR | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL => {
789 fn cast(syntax: SyntaxNode) -> Option<Self> {
790 let res = match syntax.kind() {
791 TUPLE_EXPR => Expr::TupleExpr(TupleExpr { syntax }),
792 ARRAY_EXPR => Expr::ArrayExpr(ArrayExpr { syntax }),
793 PAREN_EXPR => Expr::ParenExpr(ParenExpr { syntax }),
794 PATH_EXPR => Expr::PathExpr(PathExpr { syntax }),
795 LAMBDA_EXPR => Expr::LambdaExpr(LambdaExpr { syntax }),
796 IF_EXPR => Expr::IfExpr(IfExpr { syntax }),
797 LOOP_EXPR => Expr::LoopExpr(LoopExpr { syntax }),
798 FOR_EXPR => Expr::ForExpr(ForExpr { syntax }),
799 WHILE_EXPR => Expr::WhileExpr(WhileExpr { syntax }),
800 CONTINUE_EXPR => Expr::ContinueExpr(ContinueExpr { syntax }),
801 BREAK_EXPR => Expr::BreakExpr(BreakExpr { syntax }),
802 LABEL => Expr::Label(Label { syntax }),
803 BLOCK_EXPR => Expr::BlockExpr(BlockExpr { syntax }),
804 RETURN_EXPR => Expr::ReturnExpr(ReturnExpr { syntax }),
805 MATCH_EXPR => Expr::MatchExpr(MatchExpr { syntax }),
806 RECORD_LIT => Expr::RecordLit(RecordLit { syntax }),
807 CALL_EXPR => Expr::CallExpr(CallExpr { syntax }),
808 INDEX_EXPR => Expr::IndexExpr(IndexExpr { syntax }),
809 METHOD_CALL_EXPR => Expr::MethodCallExpr(MethodCallExpr { syntax }),
810 FIELD_EXPR => Expr::FieldExpr(FieldExpr { syntax }),
811 AWAIT_EXPR => Expr::AwaitExpr(AwaitExpr { syntax }),
812 TRY_EXPR => Expr::TryExpr(TryExpr { syntax }),
813 TRY_BLOCK_EXPR => Expr::TryBlockExpr(TryBlockExpr { syntax }),
814 CAST_EXPR => Expr::CastExpr(CastExpr { syntax }),
815 REF_EXPR => Expr::RefExpr(RefExpr { syntax }),
816 PREFIX_EXPR => Expr::PrefixExpr(PrefixExpr { syntax }),
817 RANGE_EXPR => Expr::RangeExpr(RangeExpr { syntax }),
818 BIN_EXPR => Expr::BinExpr(BinExpr { syntax }),
819 LITERAL => Expr::Literal(Literal { syntax }),
820 MACRO_CALL => Expr::MacroCall(MacroCall { syntax }),
825 fn syntax(&self) -> &SyntaxNode {
827 Expr::TupleExpr(it) => &it.syntax,
828 Expr::ArrayExpr(it) => &it.syntax,
829 Expr::ParenExpr(it) => &it.syntax,
830 Expr::PathExpr(it) => &it.syntax,
831 Expr::LambdaExpr(it) => &it.syntax,
832 Expr::IfExpr(it) => &it.syntax,
833 Expr::LoopExpr(it) => &it.syntax,
834 Expr::ForExpr(it) => &it.syntax,
835 Expr::WhileExpr(it) => &it.syntax,
836 Expr::ContinueExpr(it) => &it.syntax,
837 Expr::BreakExpr(it) => &it.syntax,
838 Expr::Label(it) => &it.syntax,
839 Expr::BlockExpr(it) => &it.syntax,
840 Expr::ReturnExpr(it) => &it.syntax,
841 Expr::MatchExpr(it) => &it.syntax,
842 Expr::RecordLit(it) => &it.syntax,
843 Expr::CallExpr(it) => &it.syntax,
844 Expr::IndexExpr(it) => &it.syntax,
845 Expr::MethodCallExpr(it) => &it.syntax,
846 Expr::FieldExpr(it) => &it.syntax,
847 Expr::AwaitExpr(it) => &it.syntax,
848 Expr::TryExpr(it) => &it.syntax,
849 Expr::TryBlockExpr(it) => &it.syntax,
850 Expr::CastExpr(it) => &it.syntax,
851 Expr::RefExpr(it) => &it.syntax,
852 Expr::PrefixExpr(it) => &it.syntax,
853 Expr::RangeExpr(it) => &it.syntax,
854 Expr::BinExpr(it) => &it.syntax,
855 Expr::Literal(it) => &it.syntax,
856 Expr::MacroCall(it) => &it.syntax,
861 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
862 pub struct ExprStmt {
863 pub(crate) syntax: SyntaxNode,
865 impl AstNode for ExprStmt {
866 fn can_cast(kind: SyntaxKind) -> bool {
872 fn cast(syntax: SyntaxNode) -> Option<Self> {
873 if Self::can_cast(syntax.kind()) {
874 Some(Self { syntax })
879 fn syntax(&self) -> &SyntaxNode {
884 pub fn expr(&self) -> Option<Expr> {
885 AstChildren::new(&self.syntax).next()
888 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
889 pub struct ExternCrateItem {
890 pub(crate) syntax: SyntaxNode,
892 impl AstNode for ExternCrateItem {
893 fn can_cast(kind: SyntaxKind) -> bool {
895 EXTERN_CRATE_ITEM => true,
899 fn cast(syntax: SyntaxNode) -> Option<Self> {
900 if Self::can_cast(syntax.kind()) {
901 Some(Self { syntax })
906 fn syntax(&self) -> &SyntaxNode {
910 impl ExternCrateItem {
911 pub fn name_ref(&self) -> Option<NameRef> {
912 AstChildren::new(&self.syntax).next()
914 pub fn alias(&self) -> Option<Alias> {
915 AstChildren::new(&self.syntax).next()
918 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
919 pub struct FieldExpr {
920 pub(crate) syntax: SyntaxNode,
922 impl AstNode for FieldExpr {
923 fn can_cast(kind: SyntaxKind) -> bool {
929 fn cast(syntax: SyntaxNode) -> Option<Self> {
930 if Self::can_cast(syntax.kind()) {
931 Some(Self { syntax })
936 fn syntax(&self) -> &SyntaxNode {
941 pub fn expr(&self) -> Option<Expr> {
942 AstChildren::new(&self.syntax).next()
944 pub fn name_ref(&self) -> Option<NameRef> {
945 AstChildren::new(&self.syntax).next()
948 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
950 pub(crate) syntax: SyntaxNode,
952 impl AstNode for FnDef {
953 fn can_cast(kind: SyntaxKind) -> bool {
959 fn cast(syntax: SyntaxNode) -> Option<Self> {
960 if Self::can_cast(syntax.kind()) {
961 Some(Self { syntax })
966 fn syntax(&self) -> &SyntaxNode {
970 impl ast::VisibilityOwner for FnDef {}
971 impl ast::NameOwner for FnDef {}
972 impl ast::TypeParamsOwner for FnDef {}
973 impl ast::AttrsOwner for FnDef {}
974 impl ast::DocCommentsOwner for FnDef {}
976 pub fn param_list(&self) -> Option<ParamList> {
977 AstChildren::new(&self.syntax).next()
979 pub fn body(&self) -> Option<Block> {
980 AstChildren::new(&self.syntax).next()
982 pub fn ret_type(&self) -> Option<RetType> {
983 AstChildren::new(&self.syntax).next()
986 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
987 pub struct FnPointerType {
988 pub(crate) syntax: SyntaxNode,
990 impl AstNode for FnPointerType {
991 fn can_cast(kind: SyntaxKind) -> bool {
993 FN_POINTER_TYPE => true,
997 fn cast(syntax: SyntaxNode) -> Option<Self> {
998 if Self::can_cast(syntax.kind()) {
999 Some(Self { syntax })
1004 fn syntax(&self) -> &SyntaxNode {
1008 impl FnPointerType {
1009 pub fn param_list(&self) -> Option<ParamList> {
1010 AstChildren::new(&self.syntax).next()
1012 pub fn ret_type(&self) -> Option<RetType> {
1013 AstChildren::new(&self.syntax).next()
1016 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1017 pub struct ForExpr {
1018 pub(crate) syntax: SyntaxNode,
1020 impl AstNode for ForExpr {
1021 fn can_cast(kind: SyntaxKind) -> bool {
1027 fn cast(syntax: SyntaxNode) -> Option<Self> {
1028 if Self::can_cast(syntax.kind()) {
1029 Some(Self { syntax })
1034 fn syntax(&self) -> &SyntaxNode {
1038 impl ast::LoopBodyOwner for ForExpr {}
1040 pub fn pat(&self) -> Option<Pat> {
1041 AstChildren::new(&self.syntax).next()
1043 pub fn iterable(&self) -> Option<Expr> {
1044 AstChildren::new(&self.syntax).next()
1047 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1048 pub struct ForType {
1049 pub(crate) syntax: SyntaxNode,
1051 impl AstNode for ForType {
1052 fn can_cast(kind: SyntaxKind) -> bool {
1058 fn cast(syntax: SyntaxNode) -> Option<Self> {
1059 if Self::can_cast(syntax.kind()) {
1060 Some(Self { syntax })
1065 fn syntax(&self) -> &SyntaxNode {
1070 pub fn type_ref(&self) -> Option<TypeRef> {
1071 AstChildren::new(&self.syntax).next()
1074 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1076 pub(crate) syntax: SyntaxNode,
1078 impl AstNode for IfExpr {
1079 fn can_cast(kind: SyntaxKind) -> bool {
1085 fn cast(syntax: SyntaxNode) -> Option<Self> {
1086 if Self::can_cast(syntax.kind()) {
1087 Some(Self { syntax })
1092 fn syntax(&self) -> &SyntaxNode {
1097 pub fn condition(&self) -> Option<Condition> {
1098 AstChildren::new(&self.syntax).next()
1101 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1102 pub struct ImplBlock {
1103 pub(crate) syntax: SyntaxNode,
1105 impl AstNode for ImplBlock {
1106 fn can_cast(kind: SyntaxKind) -> bool {
1112 fn cast(syntax: SyntaxNode) -> Option<Self> {
1113 if Self::can_cast(syntax.kind()) {
1114 Some(Self { syntax })
1119 fn syntax(&self) -> &SyntaxNode {
1123 impl ast::TypeParamsOwner for ImplBlock {}
1124 impl ast::AttrsOwner for ImplBlock {}
1126 pub fn item_list(&self) -> Option<ItemList> {
1127 AstChildren::new(&self.syntax).next()
1130 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1133 TypeAliasDef(TypeAliasDef),
1136 impl From<FnDef> for ImplItem {
1137 fn from(node: FnDef) -> ImplItem {
1138 ImplItem::FnDef(node)
1141 impl From<TypeAliasDef> for ImplItem {
1142 fn from(node: TypeAliasDef) -> ImplItem {
1143 ImplItem::TypeAliasDef(node)
1146 impl From<ConstDef> for ImplItem {
1147 fn from(node: ConstDef) -> ImplItem {
1148 ImplItem::ConstDef(node)
1151 impl AstNode for ImplItem {
1152 fn can_cast(kind: SyntaxKind) -> bool {
1154 FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true,
1158 fn cast(syntax: SyntaxNode) -> Option<Self> {
1159 let res = match syntax.kind() {
1160 FN_DEF => ImplItem::FnDef(FnDef { syntax }),
1161 TYPE_ALIAS_DEF => ImplItem::TypeAliasDef(TypeAliasDef { syntax }),
1162 CONST_DEF => ImplItem::ConstDef(ConstDef { syntax }),
1167 fn syntax(&self) -> &SyntaxNode {
1169 ImplItem::FnDef(it) => &it.syntax,
1170 ImplItem::TypeAliasDef(it) => &it.syntax,
1171 ImplItem::ConstDef(it) => &it.syntax,
1176 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1177 pub struct ImplTraitType {
1178 pub(crate) syntax: SyntaxNode,
1180 impl AstNode for ImplTraitType {
1181 fn can_cast(kind: SyntaxKind) -> bool {
1183 IMPL_TRAIT_TYPE => true,
1187 fn cast(syntax: SyntaxNode) -> Option<Self> {
1188 if Self::can_cast(syntax.kind()) {
1189 Some(Self { syntax })
1194 fn syntax(&self) -> &SyntaxNode {
1198 impl ast::TypeBoundsOwner for ImplTraitType {}
1199 impl ImplTraitType {}
1200 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1201 pub struct IndexExpr {
1202 pub(crate) syntax: SyntaxNode,
1204 impl AstNode for IndexExpr {
1205 fn can_cast(kind: SyntaxKind) -> bool {
1211 fn cast(syntax: SyntaxNode) -> Option<Self> {
1212 if Self::can_cast(syntax.kind()) {
1213 Some(Self { syntax })
1218 fn syntax(&self) -> &SyntaxNode {
1223 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1224 pub struct ItemList {
1225 pub(crate) syntax: SyntaxNode,
1227 impl AstNode for ItemList {
1228 fn can_cast(kind: SyntaxKind) -> bool {
1234 fn cast(syntax: SyntaxNode) -> Option<Self> {
1235 if Self::can_cast(syntax.kind()) {
1236 Some(Self { syntax })
1241 fn syntax(&self) -> &SyntaxNode {
1245 impl ast::FnDefOwner for ItemList {}
1246 impl ast::ModuleItemOwner for ItemList {}
1248 pub fn impl_items(&self) -> AstChildren<ImplItem> {
1249 AstChildren::new(&self.syntax)
1252 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1254 pub(crate) syntax: SyntaxNode,
1256 impl AstNode for Label {
1257 fn can_cast(kind: SyntaxKind) -> bool {
1263 fn cast(syntax: SyntaxNode) -> Option<Self> {
1264 if Self::can_cast(syntax.kind()) {
1265 Some(Self { syntax })
1270 fn syntax(&self) -> &SyntaxNode {
1275 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1276 pub struct LambdaExpr {
1277 pub(crate) syntax: SyntaxNode,
1279 impl AstNode for LambdaExpr {
1280 fn can_cast(kind: SyntaxKind) -> bool {
1282 LAMBDA_EXPR => true,
1286 fn cast(syntax: SyntaxNode) -> Option<Self> {
1287 if Self::can_cast(syntax.kind()) {
1288 Some(Self { syntax })
1293 fn syntax(&self) -> &SyntaxNode {
1298 pub fn param_list(&self) -> Option<ParamList> {
1299 AstChildren::new(&self.syntax).next()
1301 pub fn body(&self) -> Option<Expr> {
1302 AstChildren::new(&self.syntax).next()
1305 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1306 pub struct LetStmt {
1307 pub(crate) syntax: SyntaxNode,
1309 impl AstNode for LetStmt {
1310 fn can_cast(kind: SyntaxKind) -> bool {
1316 fn cast(syntax: SyntaxNode) -> Option<Self> {
1317 if Self::can_cast(syntax.kind()) {
1318 Some(Self { syntax })
1323 fn syntax(&self) -> &SyntaxNode {
1327 impl ast::TypeAscriptionOwner for LetStmt {}
1329 pub fn pat(&self) -> Option<Pat> {
1330 AstChildren::new(&self.syntax).next()
1332 pub fn initializer(&self) -> Option<Expr> {
1333 AstChildren::new(&self.syntax).next()
1336 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1337 pub struct LifetimeArg {
1338 pub(crate) syntax: SyntaxNode,
1340 impl AstNode for LifetimeArg {
1341 fn can_cast(kind: SyntaxKind) -> bool {
1343 LIFETIME_ARG => true,
1347 fn cast(syntax: SyntaxNode) -> Option<Self> {
1348 if Self::can_cast(syntax.kind()) {
1349 Some(Self { syntax })
1354 fn syntax(&self) -> &SyntaxNode {
1359 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1360 pub struct LifetimeParam {
1361 pub(crate) syntax: SyntaxNode,
1363 impl AstNode for LifetimeParam {
1364 fn can_cast(kind: SyntaxKind) -> bool {
1366 LIFETIME_PARAM => true,
1370 fn cast(syntax: SyntaxNode) -> Option<Self> {
1371 if Self::can_cast(syntax.kind()) {
1372 Some(Self { syntax })
1377 fn syntax(&self) -> &SyntaxNode {
1381 impl ast::AttrsOwner for LifetimeParam {}
1382 impl LifetimeParam {}
1383 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1384 pub struct Literal {
1385 pub(crate) syntax: SyntaxNode,
1387 impl AstNode for Literal {
1388 fn can_cast(kind: SyntaxKind) -> bool {
1394 fn cast(syntax: SyntaxNode) -> Option<Self> {
1395 if Self::can_cast(syntax.kind()) {
1396 Some(Self { syntax })
1401 fn syntax(&self) -> &SyntaxNode {
1406 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1407 pub struct LiteralPat {
1408 pub(crate) syntax: SyntaxNode,
1410 impl AstNode for LiteralPat {
1411 fn can_cast(kind: SyntaxKind) -> bool {
1413 LITERAL_PAT => true,
1417 fn cast(syntax: SyntaxNode) -> Option<Self> {
1418 if Self::can_cast(syntax.kind()) {
1419 Some(Self { syntax })
1424 fn syntax(&self) -> &SyntaxNode {
1429 pub fn literal(&self) -> Option<Literal> {
1430 AstChildren::new(&self.syntax).next()
1433 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1434 pub struct LoopExpr {
1435 pub(crate) syntax: SyntaxNode,
1437 impl AstNode for LoopExpr {
1438 fn can_cast(kind: SyntaxKind) -> bool {
1444 fn cast(syntax: SyntaxNode) -> Option<Self> {
1445 if Self::can_cast(syntax.kind()) {
1446 Some(Self { syntax })
1451 fn syntax(&self) -> &SyntaxNode {
1455 impl ast::LoopBodyOwner for LoopExpr {}
1457 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1458 pub struct MacroCall {
1459 pub(crate) syntax: SyntaxNode,
1461 impl AstNode for MacroCall {
1462 fn can_cast(kind: SyntaxKind) -> bool {
1468 fn cast(syntax: SyntaxNode) -> Option<Self> {
1469 if Self::can_cast(syntax.kind()) {
1470 Some(Self { syntax })
1475 fn syntax(&self) -> &SyntaxNode {
1479 impl ast::NameOwner for MacroCall {}
1480 impl ast::AttrsOwner for MacroCall {}
1481 impl ast::DocCommentsOwner for MacroCall {}
1483 pub fn token_tree(&self) -> Option<TokenTree> {
1484 AstChildren::new(&self.syntax).next()
1486 pub fn path(&self) -> Option<Path> {
1487 AstChildren::new(&self.syntax).next()
1490 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1491 pub struct MacroItems {
1492 pub(crate) syntax: SyntaxNode,
1494 impl AstNode for MacroItems {
1495 fn can_cast(kind: SyntaxKind) -> bool {
1497 MACRO_ITEMS => true,
1501 fn cast(syntax: SyntaxNode) -> Option<Self> {
1502 if Self::can_cast(syntax.kind()) {
1503 Some(Self { syntax })
1508 fn syntax(&self) -> &SyntaxNode {
1512 impl ast::ModuleItemOwner for MacroItems {}
1513 impl ast::FnDefOwner for MacroItems {}
1515 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1516 pub struct MacroStmts {
1517 pub(crate) syntax: SyntaxNode,
1519 impl AstNode for MacroStmts {
1520 fn can_cast(kind: SyntaxKind) -> bool {
1522 MACRO_STMTS => true,
1526 fn cast(syntax: SyntaxNode) -> Option<Self> {
1527 if Self::can_cast(syntax.kind()) {
1528 Some(Self { syntax })
1533 fn syntax(&self) -> &SyntaxNode {
1538 pub fn statements(&self) -> AstChildren<Stmt> {
1539 AstChildren::new(&self.syntax)
1541 pub fn expr(&self) -> Option<Expr> {
1542 AstChildren::new(&self.syntax).next()
1545 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1546 pub struct MatchArm {
1547 pub(crate) syntax: SyntaxNode,
1549 impl AstNode for MatchArm {
1550 fn can_cast(kind: SyntaxKind) -> bool {
1556 fn cast(syntax: SyntaxNode) -> Option<Self> {
1557 if Self::can_cast(syntax.kind()) {
1558 Some(Self { syntax })
1563 fn syntax(&self) -> &SyntaxNode {
1567 impl ast::AttrsOwner for MatchArm {}
1569 pub fn pats(&self) -> AstChildren<Pat> {
1570 AstChildren::new(&self.syntax)
1572 pub fn guard(&self) -> Option<MatchGuard> {
1573 AstChildren::new(&self.syntax).next()
1575 pub fn expr(&self) -> Option<Expr> {
1576 AstChildren::new(&self.syntax).next()
1579 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1580 pub struct MatchArmList {
1581 pub(crate) syntax: SyntaxNode,
1583 impl AstNode for MatchArmList {
1584 fn can_cast(kind: SyntaxKind) -> bool {
1586 MATCH_ARM_LIST => true,
1590 fn cast(syntax: SyntaxNode) -> Option<Self> {
1591 if Self::can_cast(syntax.kind()) {
1592 Some(Self { syntax })
1597 fn syntax(&self) -> &SyntaxNode {
1601 impl ast::AttrsOwner for MatchArmList {}
1603 pub fn arms(&self) -> AstChildren<MatchArm> {
1604 AstChildren::new(&self.syntax)
1607 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1608 pub struct MatchExpr {
1609 pub(crate) syntax: SyntaxNode,
1611 impl AstNode for MatchExpr {
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 {
1630 pub fn expr(&self) -> Option<Expr> {
1631 AstChildren::new(&self.syntax).next()
1633 pub fn match_arm_list(&self) -> Option<MatchArmList> {
1634 AstChildren::new(&self.syntax).next()
1637 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1638 pub struct MatchGuard {
1639 pub(crate) syntax: SyntaxNode,
1641 impl AstNode for MatchGuard {
1642 fn can_cast(kind: SyntaxKind) -> bool {
1644 MATCH_GUARD => true,
1648 fn cast(syntax: SyntaxNode) -> Option<Self> {
1649 if Self::can_cast(syntax.kind()) {
1650 Some(Self { syntax })
1655 fn syntax(&self) -> &SyntaxNode {
1660 pub fn expr(&self) -> Option<Expr> {
1661 AstChildren::new(&self.syntax).next()
1664 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1665 pub struct MethodCallExpr {
1666 pub(crate) syntax: SyntaxNode,
1668 impl AstNode for MethodCallExpr {
1669 fn can_cast(kind: SyntaxKind) -> bool {
1671 METHOD_CALL_EXPR => true,
1675 fn cast(syntax: SyntaxNode) -> Option<Self> {
1676 if Self::can_cast(syntax.kind()) {
1677 Some(Self { syntax })
1682 fn syntax(&self) -> &SyntaxNode {
1686 impl ast::ArgListOwner for MethodCallExpr {}
1687 impl MethodCallExpr {
1688 pub fn expr(&self) -> Option<Expr> {
1689 AstChildren::new(&self.syntax).next()
1691 pub fn name_ref(&self) -> Option<NameRef> {
1692 AstChildren::new(&self.syntax).next()
1694 pub fn type_arg_list(&self) -> Option<TypeArgList> {
1695 AstChildren::new(&self.syntax).next()
1698 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1700 pub(crate) syntax: SyntaxNode,
1702 impl AstNode for Module {
1703 fn can_cast(kind: SyntaxKind) -> bool {
1709 fn cast(syntax: SyntaxNode) -> Option<Self> {
1710 if Self::can_cast(syntax.kind()) {
1711 Some(Self { syntax })
1716 fn syntax(&self) -> &SyntaxNode {
1720 impl ast::VisibilityOwner for Module {}
1721 impl ast::NameOwner for Module {}
1722 impl ast::AttrsOwner for Module {}
1723 impl ast::DocCommentsOwner for Module {}
1725 pub fn item_list(&self) -> Option<ItemList> {
1726 AstChildren::new(&self.syntax).next()
1729 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1730 pub enum ModuleItem {
1731 StructDef(StructDef),
1735 TypeAliasDef(TypeAliasDef),
1736 ImplBlock(ImplBlock),
1738 ExternCrateItem(ExternCrateItem),
1740 StaticDef(StaticDef),
1743 impl From<StructDef> for ModuleItem {
1744 fn from(node: StructDef) -> ModuleItem {
1745 ModuleItem::StructDef(node)
1748 impl From<EnumDef> for ModuleItem {
1749 fn from(node: EnumDef) -> ModuleItem {
1750 ModuleItem::EnumDef(node)
1753 impl From<FnDef> for ModuleItem {
1754 fn from(node: FnDef) -> ModuleItem {
1755 ModuleItem::FnDef(node)
1758 impl From<TraitDef> for ModuleItem {
1759 fn from(node: TraitDef) -> ModuleItem {
1760 ModuleItem::TraitDef(node)
1763 impl From<TypeAliasDef> for ModuleItem {
1764 fn from(node: TypeAliasDef) -> ModuleItem {
1765 ModuleItem::TypeAliasDef(node)
1768 impl From<ImplBlock> for ModuleItem {
1769 fn from(node: ImplBlock) -> ModuleItem {
1770 ModuleItem::ImplBlock(node)
1773 impl From<UseItem> for ModuleItem {
1774 fn from(node: UseItem) -> ModuleItem {
1775 ModuleItem::UseItem(node)
1778 impl From<ExternCrateItem> for ModuleItem {
1779 fn from(node: ExternCrateItem) -> ModuleItem {
1780 ModuleItem::ExternCrateItem(node)
1783 impl From<ConstDef> for ModuleItem {
1784 fn from(node: ConstDef) -> ModuleItem {
1785 ModuleItem::ConstDef(node)
1788 impl From<StaticDef> for ModuleItem {
1789 fn from(node: StaticDef) -> ModuleItem {
1790 ModuleItem::StaticDef(node)
1793 impl From<Module> for ModuleItem {
1794 fn from(node: Module) -> ModuleItem {
1795 ModuleItem::Module(node)
1798 impl AstNode for ModuleItem {
1799 fn can_cast(kind: SyntaxKind) -> bool {
1801 STRUCT_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_BLOCK | USE_ITEM
1802 | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE => true,
1806 fn cast(syntax: SyntaxNode) -> Option<Self> {
1807 let res = match syntax.kind() {
1808 STRUCT_DEF => ModuleItem::StructDef(StructDef { syntax }),
1809 ENUM_DEF => ModuleItem::EnumDef(EnumDef { syntax }),
1810 FN_DEF => ModuleItem::FnDef(FnDef { syntax }),
1811 TRAIT_DEF => ModuleItem::TraitDef(TraitDef { syntax }),
1812 TYPE_ALIAS_DEF => ModuleItem::TypeAliasDef(TypeAliasDef { syntax }),
1813 IMPL_BLOCK => ModuleItem::ImplBlock(ImplBlock { syntax }),
1814 USE_ITEM => ModuleItem::UseItem(UseItem { syntax }),
1815 EXTERN_CRATE_ITEM => ModuleItem::ExternCrateItem(ExternCrateItem { syntax }),
1816 CONST_DEF => ModuleItem::ConstDef(ConstDef { syntax }),
1817 STATIC_DEF => ModuleItem::StaticDef(StaticDef { syntax }),
1818 MODULE => ModuleItem::Module(Module { syntax }),
1823 fn syntax(&self) -> &SyntaxNode {
1825 ModuleItem::StructDef(it) => &it.syntax,
1826 ModuleItem::EnumDef(it) => &it.syntax,
1827 ModuleItem::FnDef(it) => &it.syntax,
1828 ModuleItem::TraitDef(it) => &it.syntax,
1829 ModuleItem::TypeAliasDef(it) => &it.syntax,
1830 ModuleItem::ImplBlock(it) => &it.syntax,
1831 ModuleItem::UseItem(it) => &it.syntax,
1832 ModuleItem::ExternCrateItem(it) => &it.syntax,
1833 ModuleItem::ConstDef(it) => &it.syntax,
1834 ModuleItem::StaticDef(it) => &it.syntax,
1835 ModuleItem::Module(it) => &it.syntax,
1840 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1842 pub(crate) syntax: SyntaxNode,
1844 impl AstNode for Name {
1845 fn can_cast(kind: SyntaxKind) -> bool {
1851 fn cast(syntax: SyntaxNode) -> Option<Self> {
1852 if Self::can_cast(syntax.kind()) {
1853 Some(Self { syntax })
1858 fn syntax(&self) -> &SyntaxNode {
1863 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1864 pub struct NameRef {
1865 pub(crate) syntax: SyntaxNode,
1867 impl AstNode for NameRef {
1868 fn can_cast(kind: SyntaxKind) -> bool {
1874 fn cast(syntax: SyntaxNode) -> Option<Self> {
1875 if Self::can_cast(syntax.kind()) {
1876 Some(Self { syntax })
1881 fn syntax(&self) -> &SyntaxNode {
1886 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1887 pub struct NeverType {
1888 pub(crate) syntax: SyntaxNode,
1890 impl AstNode for NeverType {
1891 fn can_cast(kind: SyntaxKind) -> bool {
1897 fn cast(syntax: SyntaxNode) -> Option<Self> {
1898 if Self::can_cast(syntax.kind()) {
1899 Some(Self { syntax })
1904 fn syntax(&self) -> &SyntaxNode {
1909 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1910 pub enum NominalDef {
1911 StructDef(StructDef),
1914 impl From<StructDef> for NominalDef {
1915 fn from(node: StructDef) -> NominalDef {
1916 NominalDef::StructDef(node)
1919 impl From<EnumDef> for NominalDef {
1920 fn from(node: EnumDef) -> NominalDef {
1921 NominalDef::EnumDef(node)
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 let res = match syntax.kind() {
1933 STRUCT_DEF => NominalDef::StructDef(StructDef { syntax }),
1934 ENUM_DEF => NominalDef::EnumDef(EnumDef { syntax }),
1939 fn syntax(&self) -> &SyntaxNode {
1941 NominalDef::StructDef(it) => &it.syntax,
1942 NominalDef::EnumDef(it) => &it.syntax,
1946 impl ast::NameOwner for NominalDef {}
1947 impl ast::TypeParamsOwner for NominalDef {}
1948 impl ast::AttrsOwner for NominalDef {}
1950 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1952 pub(crate) syntax: SyntaxNode,
1954 impl AstNode for Param {
1955 fn can_cast(kind: SyntaxKind) -> bool {
1961 fn cast(syntax: SyntaxNode) -> Option<Self> {
1962 if Self::can_cast(syntax.kind()) {
1963 Some(Self { syntax })
1968 fn syntax(&self) -> &SyntaxNode {
1972 impl ast::TypeAscriptionOwner for Param {}
1973 impl ast::AttrsOwner for Param {}
1975 pub fn pat(&self) -> Option<Pat> {
1976 AstChildren::new(&self.syntax).next()
1979 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1980 pub struct ParamList {
1981 pub(crate) syntax: SyntaxNode,
1983 impl AstNode for ParamList {
1984 fn can_cast(kind: SyntaxKind) -> bool {
1990 fn cast(syntax: SyntaxNode) -> Option<Self> {
1991 if Self::can_cast(syntax.kind()) {
1992 Some(Self { syntax })
1997 fn syntax(&self) -> &SyntaxNode {
2002 pub fn params(&self) -> AstChildren<Param> {
2003 AstChildren::new(&self.syntax)
2005 pub fn self_param(&self) -> Option<SelfParam> {
2006 AstChildren::new(&self.syntax).next()
2009 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2010 pub struct ParenExpr {
2011 pub(crate) syntax: SyntaxNode,
2013 impl AstNode for ParenExpr {
2014 fn can_cast(kind: SyntaxKind) -> bool {
2020 fn cast(syntax: SyntaxNode) -> Option<Self> {
2021 if Self::can_cast(syntax.kind()) {
2022 Some(Self { syntax })
2027 fn syntax(&self) -> &SyntaxNode {
2032 pub fn expr(&self) -> Option<Expr> {
2033 AstChildren::new(&self.syntax).next()
2036 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2037 pub struct ParenType {
2038 pub(crate) syntax: SyntaxNode,
2040 impl AstNode for ParenType {
2041 fn can_cast(kind: SyntaxKind) -> bool {
2047 fn cast(syntax: SyntaxNode) -> Option<Self> {
2048 if Self::can_cast(syntax.kind()) {
2049 Some(Self { syntax })
2054 fn syntax(&self) -> &SyntaxNode {
2059 pub fn type_ref(&self) -> Option<TypeRef> {
2060 AstChildren::new(&self.syntax).next()
2063 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2067 PlaceholderPat(PlaceholderPat),
2069 RecordPat(RecordPat),
2070 TupleStructPat(TupleStructPat),
2074 LiteralPat(LiteralPat),
2076 impl From<RefPat> for Pat {
2077 fn from(node: RefPat) -> Pat {
2081 impl From<BindPat> for Pat {
2082 fn from(node: BindPat) -> Pat {
2086 impl From<PlaceholderPat> for Pat {
2087 fn from(node: PlaceholderPat) -> Pat {
2088 Pat::PlaceholderPat(node)
2091 impl From<PathPat> for Pat {
2092 fn from(node: PathPat) -> Pat {
2096 impl From<RecordPat> for Pat {
2097 fn from(node: RecordPat) -> Pat {
2098 Pat::RecordPat(node)
2101 impl From<TupleStructPat> for Pat {
2102 fn from(node: TupleStructPat) -> Pat {
2103 Pat::TupleStructPat(node)
2106 impl From<TuplePat> for Pat {
2107 fn from(node: TuplePat) -> Pat {
2111 impl From<SlicePat> for Pat {
2112 fn from(node: SlicePat) -> Pat {
2116 impl From<RangePat> for Pat {
2117 fn from(node: RangePat) -> Pat {
2121 impl From<LiteralPat> for Pat {
2122 fn from(node: LiteralPat) -> Pat {
2123 Pat::LiteralPat(node)
2126 impl AstNode for Pat {
2127 fn can_cast(kind: SyntaxKind) -> bool {
2129 REF_PAT | BIND_PAT | PLACEHOLDER_PAT | PATH_PAT | RECORD_PAT | TUPLE_STRUCT_PAT
2130 | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => true,
2134 fn cast(syntax: SyntaxNode) -> Option<Self> {
2135 let res = match syntax.kind() {
2136 REF_PAT => Pat::RefPat(RefPat { syntax }),
2137 BIND_PAT => Pat::BindPat(BindPat { syntax }),
2138 PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }),
2139 PATH_PAT => Pat::PathPat(PathPat { syntax }),
2140 RECORD_PAT => Pat::RecordPat(RecordPat { syntax }),
2141 TUPLE_STRUCT_PAT => Pat::TupleStructPat(TupleStructPat { syntax }),
2142 TUPLE_PAT => Pat::TuplePat(TuplePat { syntax }),
2143 SLICE_PAT => Pat::SlicePat(SlicePat { syntax }),
2144 RANGE_PAT => Pat::RangePat(RangePat { syntax }),
2145 LITERAL_PAT => Pat::LiteralPat(LiteralPat { syntax }),
2150 fn syntax(&self) -> &SyntaxNode {
2152 Pat::RefPat(it) => &it.syntax,
2153 Pat::BindPat(it) => &it.syntax,
2154 Pat::PlaceholderPat(it) => &it.syntax,
2155 Pat::PathPat(it) => &it.syntax,
2156 Pat::RecordPat(it) => &it.syntax,
2157 Pat::TupleStructPat(it) => &it.syntax,
2158 Pat::TuplePat(it) => &it.syntax,
2159 Pat::SlicePat(it) => &it.syntax,
2160 Pat::RangePat(it) => &it.syntax,
2161 Pat::LiteralPat(it) => &it.syntax,
2166 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2168 pub(crate) syntax: SyntaxNode,
2170 impl AstNode for Path {
2171 fn can_cast(kind: SyntaxKind) -> bool {
2177 fn cast(syntax: SyntaxNode) -> Option<Self> {
2178 if Self::can_cast(syntax.kind()) {
2179 Some(Self { syntax })
2184 fn syntax(&self) -> &SyntaxNode {
2189 pub fn segment(&self) -> Option<PathSegment> {
2190 AstChildren::new(&self.syntax).next()
2192 pub fn qualifier(&self) -> Option<Path> {
2193 AstChildren::new(&self.syntax).next()
2196 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2197 pub struct PathExpr {
2198 pub(crate) syntax: SyntaxNode,
2200 impl AstNode for PathExpr {
2201 fn can_cast(kind: SyntaxKind) -> bool {
2207 fn cast(syntax: SyntaxNode) -> Option<Self> {
2208 if Self::can_cast(syntax.kind()) {
2209 Some(Self { syntax })
2214 fn syntax(&self) -> &SyntaxNode {
2219 pub fn path(&self) -> Option<Path> {
2220 AstChildren::new(&self.syntax).next()
2223 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2224 pub struct PathPat {
2225 pub(crate) syntax: SyntaxNode,
2227 impl AstNode for PathPat {
2228 fn can_cast(kind: SyntaxKind) -> bool {
2234 fn cast(syntax: SyntaxNode) -> Option<Self> {
2235 if Self::can_cast(syntax.kind()) {
2236 Some(Self { syntax })
2241 fn syntax(&self) -> &SyntaxNode {
2246 pub fn path(&self) -> Option<Path> {
2247 AstChildren::new(&self.syntax).next()
2250 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2251 pub struct PathSegment {
2252 pub(crate) syntax: SyntaxNode,
2254 impl AstNode for PathSegment {
2255 fn can_cast(kind: SyntaxKind) -> bool {
2257 PATH_SEGMENT => true,
2261 fn cast(syntax: SyntaxNode) -> Option<Self> {
2262 if Self::can_cast(syntax.kind()) {
2263 Some(Self { syntax })
2268 fn syntax(&self) -> &SyntaxNode {
2273 pub fn name_ref(&self) -> Option<NameRef> {
2274 AstChildren::new(&self.syntax).next()
2276 pub fn type_arg_list(&self) -> Option<TypeArgList> {
2277 AstChildren::new(&self.syntax).next()
2280 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2281 pub struct PathType {
2282 pub(crate) syntax: SyntaxNode,
2284 impl AstNode for PathType {
2285 fn can_cast(kind: SyntaxKind) -> bool {
2291 fn cast(syntax: SyntaxNode) -> Option<Self> {
2292 if Self::can_cast(syntax.kind()) {
2293 Some(Self { syntax })
2298 fn syntax(&self) -> &SyntaxNode {
2303 pub fn path(&self) -> Option<Path> {
2304 AstChildren::new(&self.syntax).next()
2307 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2308 pub struct PlaceholderPat {
2309 pub(crate) syntax: SyntaxNode,
2311 impl AstNode for PlaceholderPat {
2312 fn can_cast(kind: SyntaxKind) -> bool {
2314 PLACEHOLDER_PAT => true,
2318 fn cast(syntax: SyntaxNode) -> Option<Self> {
2319 if Self::can_cast(syntax.kind()) {
2320 Some(Self { syntax })
2325 fn syntax(&self) -> &SyntaxNode {
2329 impl PlaceholderPat {}
2330 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2331 pub struct PlaceholderType {
2332 pub(crate) syntax: SyntaxNode,
2334 impl AstNode for PlaceholderType {
2335 fn can_cast(kind: SyntaxKind) -> bool {
2337 PLACEHOLDER_TYPE => true,
2341 fn cast(syntax: SyntaxNode) -> Option<Self> {
2342 if Self::can_cast(syntax.kind()) {
2343 Some(Self { syntax })
2348 fn syntax(&self) -> &SyntaxNode {
2352 impl PlaceholderType {}
2353 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2354 pub struct PointerType {
2355 pub(crate) syntax: SyntaxNode,
2357 impl AstNode for PointerType {
2358 fn can_cast(kind: SyntaxKind) -> bool {
2360 POINTER_TYPE => true,
2364 fn cast(syntax: SyntaxNode) -> Option<Self> {
2365 if Self::can_cast(syntax.kind()) {
2366 Some(Self { syntax })
2371 fn syntax(&self) -> &SyntaxNode {
2376 pub fn type_ref(&self) -> Option<TypeRef> {
2377 AstChildren::new(&self.syntax).next()
2380 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2381 pub struct PrefixExpr {
2382 pub(crate) syntax: SyntaxNode,
2384 impl AstNode for PrefixExpr {
2385 fn can_cast(kind: SyntaxKind) -> bool {
2387 PREFIX_EXPR => true,
2391 fn cast(syntax: SyntaxNode) -> Option<Self> {
2392 if Self::can_cast(syntax.kind()) {
2393 Some(Self { syntax })
2398 fn syntax(&self) -> &SyntaxNode {
2403 pub fn expr(&self) -> Option<Expr> {
2404 AstChildren::new(&self.syntax).next()
2407 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2408 pub struct RangeExpr {
2409 pub(crate) syntax: SyntaxNode,
2411 impl AstNode for RangeExpr {
2412 fn can_cast(kind: SyntaxKind) -> bool {
2418 fn cast(syntax: SyntaxNode) -> Option<Self> {
2419 if Self::can_cast(syntax.kind()) {
2420 Some(Self { syntax })
2425 fn syntax(&self) -> &SyntaxNode {
2430 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2431 pub struct RangePat {
2432 pub(crate) syntax: SyntaxNode,
2434 impl AstNode for RangePat {
2435 fn can_cast(kind: SyntaxKind) -> bool {
2441 fn cast(syntax: SyntaxNode) -> Option<Self> {
2442 if Self::can_cast(syntax.kind()) {
2443 Some(Self { syntax })
2448 fn syntax(&self) -> &SyntaxNode {
2453 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2454 pub struct RecordField {
2455 pub(crate) syntax: SyntaxNode,
2457 impl AstNode for RecordField {
2458 fn can_cast(kind: SyntaxKind) -> bool {
2460 RECORD_FIELD => true,
2464 fn cast(syntax: SyntaxNode) -> Option<Self> {
2465 if Self::can_cast(syntax.kind()) {
2466 Some(Self { syntax })
2471 fn syntax(&self) -> &SyntaxNode {
2476 pub fn name_ref(&self) -> Option<NameRef> {
2477 AstChildren::new(&self.syntax).next()
2479 pub fn expr(&self) -> Option<Expr> {
2480 AstChildren::new(&self.syntax).next()
2483 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2484 pub struct RecordFieldDef {
2485 pub(crate) syntax: SyntaxNode,
2487 impl AstNode for RecordFieldDef {
2488 fn can_cast(kind: SyntaxKind) -> bool {
2490 RECORD_FIELD_DEF => true,
2494 fn cast(syntax: SyntaxNode) -> Option<Self> {
2495 if Self::can_cast(syntax.kind()) {
2496 Some(Self { syntax })
2501 fn syntax(&self) -> &SyntaxNode {
2505 impl ast::VisibilityOwner for RecordFieldDef {}
2506 impl ast::NameOwner for RecordFieldDef {}
2507 impl ast::AttrsOwner for RecordFieldDef {}
2508 impl ast::DocCommentsOwner for RecordFieldDef {}
2509 impl ast::TypeAscriptionOwner for RecordFieldDef {}
2510 impl RecordFieldDef {}
2511 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2512 pub struct RecordFieldDefList {
2513 pub(crate) syntax: SyntaxNode,
2515 impl AstNode for RecordFieldDefList {
2516 fn can_cast(kind: SyntaxKind) -> bool {
2518 RECORD_FIELD_DEF_LIST => true,
2522 fn cast(syntax: SyntaxNode) -> Option<Self> {
2523 if Self::can_cast(syntax.kind()) {
2524 Some(Self { syntax })
2529 fn syntax(&self) -> &SyntaxNode {
2533 impl RecordFieldDefList {
2534 pub fn fields(&self) -> AstChildren<RecordFieldDef> {
2535 AstChildren::new(&self.syntax)
2538 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2539 pub struct RecordFieldList {
2540 pub(crate) syntax: SyntaxNode,
2542 impl AstNode for RecordFieldList {
2543 fn can_cast(kind: SyntaxKind) -> bool {
2545 RECORD_FIELD_LIST => true,
2549 fn cast(syntax: SyntaxNode) -> Option<Self> {
2550 if Self::can_cast(syntax.kind()) {
2551 Some(Self { syntax })
2556 fn syntax(&self) -> &SyntaxNode {
2560 impl RecordFieldList {
2561 pub fn fields(&self) -> AstChildren<RecordField> {
2562 AstChildren::new(&self.syntax)
2564 pub fn spread(&self) -> Option<Expr> {
2565 AstChildren::new(&self.syntax).next()
2568 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2569 pub struct RecordFieldPat {
2570 pub(crate) syntax: SyntaxNode,
2572 impl AstNode for RecordFieldPat {
2573 fn can_cast(kind: SyntaxKind) -> bool {
2575 RECORD_FIELD_PAT => true,
2579 fn cast(syntax: SyntaxNode) -> Option<Self> {
2580 if Self::can_cast(syntax.kind()) {
2581 Some(Self { syntax })
2586 fn syntax(&self) -> &SyntaxNode {
2590 impl ast::NameOwner for RecordFieldPat {}
2591 impl RecordFieldPat {
2592 pub fn pat(&self) -> Option<Pat> {
2593 AstChildren::new(&self.syntax).next()
2596 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2597 pub struct RecordFieldPatList {
2598 pub(crate) syntax: SyntaxNode,
2600 impl AstNode for RecordFieldPatList {
2601 fn can_cast(kind: SyntaxKind) -> bool {
2603 RECORD_FIELD_PAT_LIST => true,
2607 fn cast(syntax: SyntaxNode) -> Option<Self> {
2608 if Self::can_cast(syntax.kind()) {
2609 Some(Self { syntax })
2614 fn syntax(&self) -> &SyntaxNode {
2618 impl RecordFieldPatList {
2619 pub fn record_field_pats(&self) -> AstChildren<RecordFieldPat> {
2620 AstChildren::new(&self.syntax)
2622 pub fn bind_pats(&self) -> AstChildren<BindPat> {
2623 AstChildren::new(&self.syntax)
2626 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2627 pub struct RecordLit {
2628 pub(crate) syntax: SyntaxNode,
2630 impl AstNode for RecordLit {
2631 fn can_cast(kind: SyntaxKind) -> bool {
2637 fn cast(syntax: SyntaxNode) -> Option<Self> {
2638 if Self::can_cast(syntax.kind()) {
2639 Some(Self { syntax })
2644 fn syntax(&self) -> &SyntaxNode {
2649 pub fn path(&self) -> Option<Path> {
2650 AstChildren::new(&self.syntax).next()
2652 pub fn record_field_list(&self) -> Option<RecordFieldList> {
2653 AstChildren::new(&self.syntax).next()
2656 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2657 pub struct RecordPat {
2658 pub(crate) syntax: SyntaxNode,
2660 impl AstNode for RecordPat {
2661 fn can_cast(kind: SyntaxKind) -> bool {
2667 fn cast(syntax: SyntaxNode) -> Option<Self> {
2668 if Self::can_cast(syntax.kind()) {
2669 Some(Self { syntax })
2674 fn syntax(&self) -> &SyntaxNode {
2679 pub fn record_field_pat_list(&self) -> Option<RecordFieldPatList> {
2680 AstChildren::new(&self.syntax).next()
2682 pub fn path(&self) -> Option<Path> {
2683 AstChildren::new(&self.syntax).next()
2686 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2687 pub struct RefExpr {
2688 pub(crate) syntax: SyntaxNode,
2690 impl AstNode for RefExpr {
2691 fn can_cast(kind: SyntaxKind) -> bool {
2697 fn cast(syntax: SyntaxNode) -> Option<Self> {
2698 if Self::can_cast(syntax.kind()) {
2699 Some(Self { syntax })
2704 fn syntax(&self) -> &SyntaxNode {
2709 pub fn expr(&self) -> Option<Expr> {
2710 AstChildren::new(&self.syntax).next()
2713 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2715 pub(crate) syntax: SyntaxNode,
2717 impl AstNode for RefPat {
2718 fn can_cast(kind: SyntaxKind) -> bool {
2724 fn cast(syntax: SyntaxNode) -> Option<Self> {
2725 if Self::can_cast(syntax.kind()) {
2726 Some(Self { syntax })
2731 fn syntax(&self) -> &SyntaxNode {
2736 pub fn pat(&self) -> Option<Pat> {
2737 AstChildren::new(&self.syntax).next()
2740 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2741 pub struct ReferenceType {
2742 pub(crate) syntax: SyntaxNode,
2744 impl AstNode for ReferenceType {
2745 fn can_cast(kind: SyntaxKind) -> bool {
2747 REFERENCE_TYPE => true,
2751 fn cast(syntax: SyntaxNode) -> Option<Self> {
2752 if Self::can_cast(syntax.kind()) {
2753 Some(Self { syntax })
2758 fn syntax(&self) -> &SyntaxNode {
2762 impl ReferenceType {
2763 pub fn type_ref(&self) -> Option<TypeRef> {
2764 AstChildren::new(&self.syntax).next()
2767 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2768 pub struct RetType {
2769 pub(crate) syntax: SyntaxNode,
2771 impl AstNode for RetType {
2772 fn can_cast(kind: SyntaxKind) -> bool {
2778 fn cast(syntax: SyntaxNode) -> Option<Self> {
2779 if Self::can_cast(syntax.kind()) {
2780 Some(Self { syntax })
2785 fn syntax(&self) -> &SyntaxNode {
2790 pub fn type_ref(&self) -> Option<TypeRef> {
2791 AstChildren::new(&self.syntax).next()
2794 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2795 pub struct ReturnExpr {
2796 pub(crate) syntax: SyntaxNode,
2798 impl AstNode for ReturnExpr {
2799 fn can_cast(kind: SyntaxKind) -> bool {
2801 RETURN_EXPR => true,
2805 fn cast(syntax: SyntaxNode) -> Option<Self> {
2806 if Self::can_cast(syntax.kind()) {
2807 Some(Self { syntax })
2812 fn syntax(&self) -> &SyntaxNode {
2817 pub fn expr(&self) -> Option<Expr> {
2818 AstChildren::new(&self.syntax).next()
2821 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2822 pub struct SelfParam {
2823 pub(crate) syntax: SyntaxNode,
2825 impl AstNode for SelfParam {
2826 fn can_cast(kind: SyntaxKind) -> bool {
2832 fn cast(syntax: SyntaxNode) -> Option<Self> {
2833 if Self::can_cast(syntax.kind()) {
2834 Some(Self { syntax })
2839 fn syntax(&self) -> &SyntaxNode {
2843 impl ast::TypeAscriptionOwner for SelfParam {}
2844 impl ast::AttrsOwner for SelfParam {}
2846 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2847 pub struct SlicePat {
2848 pub(crate) syntax: SyntaxNode,
2850 impl AstNode for SlicePat {
2851 fn can_cast(kind: SyntaxKind) -> bool {
2857 fn cast(syntax: SyntaxNode) -> Option<Self> {
2858 if Self::can_cast(syntax.kind()) {
2859 Some(Self { syntax })
2864 fn syntax(&self) -> &SyntaxNode {
2869 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2870 pub struct SliceType {
2871 pub(crate) syntax: SyntaxNode,
2873 impl AstNode for SliceType {
2874 fn can_cast(kind: SyntaxKind) -> bool {
2880 fn cast(syntax: SyntaxNode) -> Option<Self> {
2881 if Self::can_cast(syntax.kind()) {
2882 Some(Self { syntax })
2887 fn syntax(&self) -> &SyntaxNode {
2892 pub fn type_ref(&self) -> Option<TypeRef> {
2893 AstChildren::new(&self.syntax).next()
2896 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2897 pub struct SourceFile {
2898 pub(crate) syntax: SyntaxNode,
2900 impl AstNode for SourceFile {
2901 fn can_cast(kind: SyntaxKind) -> bool {
2903 SOURCE_FILE => true,
2907 fn cast(syntax: SyntaxNode) -> Option<Self> {
2908 if Self::can_cast(syntax.kind()) {
2909 Some(Self { syntax })
2914 fn syntax(&self) -> &SyntaxNode {
2918 impl ast::ModuleItemOwner for SourceFile {}
2919 impl ast::FnDefOwner for SourceFile {}
2921 pub fn modules(&self) -> AstChildren<Module> {
2922 AstChildren::new(&self.syntax)
2925 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2926 pub struct StaticDef {
2927 pub(crate) syntax: SyntaxNode,
2929 impl AstNode for StaticDef {
2930 fn can_cast(kind: SyntaxKind) -> bool {
2936 fn cast(syntax: SyntaxNode) -> Option<Self> {
2937 if Self::can_cast(syntax.kind()) {
2938 Some(Self { syntax })
2943 fn syntax(&self) -> &SyntaxNode {
2947 impl ast::VisibilityOwner for StaticDef {}
2948 impl ast::NameOwner for StaticDef {}
2949 impl ast::TypeParamsOwner for StaticDef {}
2950 impl ast::AttrsOwner for StaticDef {}
2951 impl ast::DocCommentsOwner for StaticDef {}
2952 impl ast::TypeAscriptionOwner for StaticDef {}
2954 pub fn body(&self) -> Option<Expr> {
2955 AstChildren::new(&self.syntax).next()
2958 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2963 impl From<ExprStmt> for Stmt {
2964 fn from(node: ExprStmt) -> Stmt {
2965 Stmt::ExprStmt(node)
2968 impl From<LetStmt> for Stmt {
2969 fn from(node: LetStmt) -> Stmt {
2973 impl AstNode for Stmt {
2974 fn can_cast(kind: SyntaxKind) -> bool {
2976 EXPR_STMT | LET_STMT => true,
2980 fn cast(syntax: SyntaxNode) -> Option<Self> {
2981 let res = match syntax.kind() {
2982 EXPR_STMT => Stmt::ExprStmt(ExprStmt { syntax }),
2983 LET_STMT => Stmt::LetStmt(LetStmt { syntax }),
2988 fn syntax(&self) -> &SyntaxNode {
2990 Stmt::ExprStmt(it) => &it.syntax,
2991 Stmt::LetStmt(it) => &it.syntax,
2996 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2997 pub struct StructDef {
2998 pub(crate) syntax: SyntaxNode,
3000 impl AstNode for StructDef {
3001 fn can_cast(kind: SyntaxKind) -> bool {
3007 fn cast(syntax: SyntaxNode) -> Option<Self> {
3008 if Self::can_cast(syntax.kind()) {
3009 Some(Self { syntax })
3014 fn syntax(&self) -> &SyntaxNode {
3018 impl ast::VisibilityOwner for StructDef {}
3019 impl ast::NameOwner for StructDef {}
3020 impl ast::TypeParamsOwner for StructDef {}
3021 impl ast::AttrsOwner for StructDef {}
3022 impl ast::DocCommentsOwner for StructDef {}
3024 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3025 pub struct TokenTree {
3026 pub(crate) syntax: SyntaxNode,
3028 impl AstNode for TokenTree {
3029 fn can_cast(kind: SyntaxKind) -> bool {
3035 fn cast(syntax: SyntaxNode) -> Option<Self> {
3036 if Self::can_cast(syntax.kind()) {
3037 Some(Self { syntax })
3042 fn syntax(&self) -> &SyntaxNode {
3047 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3048 pub struct TraitDef {
3049 pub(crate) syntax: SyntaxNode,
3051 impl AstNode for TraitDef {
3052 fn can_cast(kind: SyntaxKind) -> bool {
3058 fn cast(syntax: SyntaxNode) -> Option<Self> {
3059 if Self::can_cast(syntax.kind()) {
3060 Some(Self { syntax })
3065 fn syntax(&self) -> &SyntaxNode {
3069 impl ast::VisibilityOwner for TraitDef {}
3070 impl ast::NameOwner for TraitDef {}
3071 impl ast::AttrsOwner for TraitDef {}
3072 impl ast::DocCommentsOwner for TraitDef {}
3073 impl ast::TypeParamsOwner for TraitDef {}
3074 impl ast::TypeBoundsOwner for TraitDef {}
3076 pub fn item_list(&self) -> Option<ItemList> {
3077 AstChildren::new(&self.syntax).next()
3080 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3081 pub struct TryBlockExpr {
3082 pub(crate) syntax: SyntaxNode,
3084 impl AstNode for TryBlockExpr {
3085 fn can_cast(kind: SyntaxKind) -> bool {
3087 TRY_BLOCK_EXPR => true,
3091 fn cast(syntax: SyntaxNode) -> Option<Self> {
3092 if Self::can_cast(syntax.kind()) {
3093 Some(Self { syntax })
3098 fn syntax(&self) -> &SyntaxNode {
3102 impl ast::TryBlockBodyOwner for TryBlockExpr {}
3103 impl TryBlockExpr {}
3104 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3105 pub struct TryExpr {
3106 pub(crate) syntax: SyntaxNode,
3108 impl AstNode for TryExpr {
3109 fn can_cast(kind: SyntaxKind) -> bool {
3115 fn cast(syntax: SyntaxNode) -> Option<Self> {
3116 if Self::can_cast(syntax.kind()) {
3117 Some(Self { syntax })
3122 fn syntax(&self) -> &SyntaxNode {
3127 pub fn expr(&self) -> Option<Expr> {
3128 AstChildren::new(&self.syntax).next()
3131 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3132 pub struct TupleExpr {
3133 pub(crate) syntax: SyntaxNode,
3135 impl AstNode for TupleExpr {
3136 fn can_cast(kind: SyntaxKind) -> bool {
3142 fn cast(syntax: SyntaxNode) -> Option<Self> {
3143 if Self::can_cast(syntax.kind()) {
3144 Some(Self { syntax })
3149 fn syntax(&self) -> &SyntaxNode {
3154 pub fn exprs(&self) -> AstChildren<Expr> {
3155 AstChildren::new(&self.syntax)
3158 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3159 pub struct TupleFieldDef {
3160 pub(crate) syntax: SyntaxNode,
3162 impl AstNode for TupleFieldDef {
3163 fn can_cast(kind: SyntaxKind) -> bool {
3165 TUPLE_FIELD_DEF => true,
3169 fn cast(syntax: SyntaxNode) -> Option<Self> {
3170 if Self::can_cast(syntax.kind()) {
3171 Some(Self { syntax })
3176 fn syntax(&self) -> &SyntaxNode {
3180 impl ast::VisibilityOwner for TupleFieldDef {}
3181 impl ast::AttrsOwner for TupleFieldDef {}
3182 impl TupleFieldDef {
3183 pub fn type_ref(&self) -> Option<TypeRef> {
3184 AstChildren::new(&self.syntax).next()
3187 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3188 pub struct TupleFieldDefList {
3189 pub(crate) syntax: SyntaxNode,
3191 impl AstNode for TupleFieldDefList {
3192 fn can_cast(kind: SyntaxKind) -> bool {
3194 TUPLE_FIELD_DEF_LIST => true,
3198 fn cast(syntax: SyntaxNode) -> Option<Self> {
3199 if Self::can_cast(syntax.kind()) {
3200 Some(Self { syntax })
3205 fn syntax(&self) -> &SyntaxNode {
3209 impl TupleFieldDefList {
3210 pub fn fields(&self) -> AstChildren<TupleFieldDef> {
3211 AstChildren::new(&self.syntax)
3214 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3215 pub struct TuplePat {
3216 pub(crate) syntax: SyntaxNode,
3218 impl AstNode for TuplePat {
3219 fn can_cast(kind: SyntaxKind) -> bool {
3225 fn cast(syntax: SyntaxNode) -> Option<Self> {
3226 if Self::can_cast(syntax.kind()) {
3227 Some(Self { syntax })
3232 fn syntax(&self) -> &SyntaxNode {
3237 pub fn args(&self) -> AstChildren<Pat> {
3238 AstChildren::new(&self.syntax)
3241 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3242 pub struct TupleStructPat {
3243 pub(crate) syntax: SyntaxNode,
3245 impl AstNode for TupleStructPat {
3246 fn can_cast(kind: SyntaxKind) -> bool {
3248 TUPLE_STRUCT_PAT => true,
3252 fn cast(syntax: SyntaxNode) -> Option<Self> {
3253 if Self::can_cast(syntax.kind()) {
3254 Some(Self { syntax })
3259 fn syntax(&self) -> &SyntaxNode {
3263 impl TupleStructPat {
3264 pub fn args(&self) -> AstChildren<Pat> {
3265 AstChildren::new(&self.syntax)
3267 pub fn path(&self) -> Option<Path> {
3268 AstChildren::new(&self.syntax).next()
3271 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3272 pub struct TupleType {
3273 pub(crate) syntax: SyntaxNode,
3275 impl AstNode for TupleType {
3276 fn can_cast(kind: SyntaxKind) -> bool {
3282 fn cast(syntax: SyntaxNode) -> Option<Self> {
3283 if Self::can_cast(syntax.kind()) {
3284 Some(Self { syntax })
3289 fn syntax(&self) -> &SyntaxNode {
3294 pub fn fields(&self) -> AstChildren<TypeRef> {
3295 AstChildren::new(&self.syntax)
3298 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3299 pub struct TypeAliasDef {
3300 pub(crate) syntax: SyntaxNode,
3302 impl AstNode for TypeAliasDef {
3303 fn can_cast(kind: SyntaxKind) -> bool {
3305 TYPE_ALIAS_DEF => true,
3309 fn cast(syntax: SyntaxNode) -> Option<Self> {
3310 if Self::can_cast(syntax.kind()) {
3311 Some(Self { syntax })
3316 fn syntax(&self) -> &SyntaxNode {
3320 impl ast::VisibilityOwner for TypeAliasDef {}
3321 impl ast::NameOwner for TypeAliasDef {}
3322 impl ast::TypeParamsOwner for TypeAliasDef {}
3323 impl ast::AttrsOwner for TypeAliasDef {}
3324 impl ast::DocCommentsOwner for TypeAliasDef {}
3325 impl ast::TypeBoundsOwner for TypeAliasDef {}
3327 pub fn type_ref(&self) -> Option<TypeRef> {
3328 AstChildren::new(&self.syntax).next()
3331 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3332 pub struct TypeArg {
3333 pub(crate) syntax: SyntaxNode,
3335 impl AstNode for TypeArg {
3336 fn can_cast(kind: SyntaxKind) -> bool {
3342 fn cast(syntax: SyntaxNode) -> Option<Self> {
3343 if Self::can_cast(syntax.kind()) {
3344 Some(Self { syntax })
3349 fn syntax(&self) -> &SyntaxNode {
3354 pub fn type_ref(&self) -> Option<TypeRef> {
3355 AstChildren::new(&self.syntax).next()
3358 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3359 pub struct TypeArgList {
3360 pub(crate) syntax: SyntaxNode,
3362 impl AstNode for TypeArgList {
3363 fn can_cast(kind: SyntaxKind) -> bool {
3365 TYPE_ARG_LIST => true,
3369 fn cast(syntax: SyntaxNode) -> Option<Self> {
3370 if Self::can_cast(syntax.kind()) {
3371 Some(Self { syntax })
3376 fn syntax(&self) -> &SyntaxNode {
3381 pub fn type_args(&self) -> AstChildren<TypeArg> {
3382 AstChildren::new(&self.syntax)
3384 pub fn lifetime_args(&self) -> AstChildren<LifetimeArg> {
3385 AstChildren::new(&self.syntax)
3387 pub fn assoc_type_args(&self) -> AstChildren<AssocTypeArg> {
3388 AstChildren::new(&self.syntax)
3391 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3392 pub struct TypeBound {
3393 pub(crate) syntax: SyntaxNode,
3395 impl AstNode for TypeBound {
3396 fn can_cast(kind: SyntaxKind) -> bool {
3402 fn cast(syntax: SyntaxNode) -> Option<Self> {
3403 if Self::can_cast(syntax.kind()) {
3404 Some(Self { syntax })
3409 fn syntax(&self) -> &SyntaxNode {
3414 pub fn type_ref(&self) -> Option<TypeRef> {
3415 AstChildren::new(&self.syntax).next()
3418 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3419 pub struct TypeBoundList {
3420 pub(crate) syntax: SyntaxNode,
3422 impl AstNode for TypeBoundList {
3423 fn can_cast(kind: SyntaxKind) -> bool {
3425 TYPE_BOUND_LIST => true,
3429 fn cast(syntax: SyntaxNode) -> Option<Self> {
3430 if Self::can_cast(syntax.kind()) {
3431 Some(Self { syntax })
3436 fn syntax(&self) -> &SyntaxNode {
3440 impl TypeBoundList {
3441 pub fn bounds(&self) -> AstChildren<TypeBound> {
3442 AstChildren::new(&self.syntax)
3445 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3446 pub struct TypeParam {
3447 pub(crate) syntax: SyntaxNode,
3449 impl AstNode for TypeParam {
3450 fn can_cast(kind: SyntaxKind) -> bool {
3456 fn cast(syntax: SyntaxNode) -> Option<Self> {
3457 if Self::can_cast(syntax.kind()) {
3458 Some(Self { syntax })
3463 fn syntax(&self) -> &SyntaxNode {
3467 impl ast::NameOwner for TypeParam {}
3468 impl ast::AttrsOwner for TypeParam {}
3469 impl ast::TypeBoundsOwner for TypeParam {}
3470 impl ast::DefaultTypeParamOwner for TypeParam {}
3472 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3473 pub struct TypeParamList {
3474 pub(crate) syntax: SyntaxNode,
3476 impl AstNode for TypeParamList {
3477 fn can_cast(kind: SyntaxKind) -> bool {
3479 TYPE_PARAM_LIST => true,
3483 fn cast(syntax: SyntaxNode) -> Option<Self> {
3484 if Self::can_cast(syntax.kind()) {
3485 Some(Self { syntax })
3490 fn syntax(&self) -> &SyntaxNode {
3494 impl TypeParamList {
3495 pub fn type_params(&self) -> AstChildren<TypeParam> {
3496 AstChildren::new(&self.syntax)
3498 pub fn lifetime_params(&self) -> AstChildren<LifetimeParam> {
3499 AstChildren::new(&self.syntax)
3502 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3504 ParenType(ParenType),
3505 TupleType(TupleType),
3506 NeverType(NeverType),
3508 PointerType(PointerType),
3509 ArrayType(ArrayType),
3510 SliceType(SliceType),
3511 ReferenceType(ReferenceType),
3512 PlaceholderType(PlaceholderType),
3513 FnPointerType(FnPointerType),
3515 ImplTraitType(ImplTraitType),
3516 DynTraitType(DynTraitType),
3518 impl From<ParenType> for TypeRef {
3519 fn from(node: ParenType) -> TypeRef {
3520 TypeRef::ParenType(node)
3523 impl From<TupleType> for TypeRef {
3524 fn from(node: TupleType) -> TypeRef {
3525 TypeRef::TupleType(node)
3528 impl From<NeverType> for TypeRef {
3529 fn from(node: NeverType) -> TypeRef {
3530 TypeRef::NeverType(node)
3533 impl From<PathType> for TypeRef {
3534 fn from(node: PathType) -> TypeRef {
3535 TypeRef::PathType(node)
3538 impl From<PointerType> for TypeRef {
3539 fn from(node: PointerType) -> TypeRef {
3540 TypeRef::PointerType(node)
3543 impl From<ArrayType> for TypeRef {
3544 fn from(node: ArrayType) -> TypeRef {
3545 TypeRef::ArrayType(node)
3548 impl From<SliceType> for TypeRef {
3549 fn from(node: SliceType) -> TypeRef {
3550 TypeRef::SliceType(node)
3553 impl From<ReferenceType> for TypeRef {
3554 fn from(node: ReferenceType) -> TypeRef {
3555 TypeRef::ReferenceType(node)
3558 impl From<PlaceholderType> for TypeRef {
3559 fn from(node: PlaceholderType) -> TypeRef {
3560 TypeRef::PlaceholderType(node)
3563 impl From<FnPointerType> for TypeRef {
3564 fn from(node: FnPointerType) -> TypeRef {
3565 TypeRef::FnPointerType(node)
3568 impl From<ForType> for TypeRef {
3569 fn from(node: ForType) -> TypeRef {
3570 TypeRef::ForType(node)
3573 impl From<ImplTraitType> for TypeRef {
3574 fn from(node: ImplTraitType) -> TypeRef {
3575 TypeRef::ImplTraitType(node)
3578 impl From<DynTraitType> for TypeRef {
3579 fn from(node: DynTraitType) -> TypeRef {
3580 TypeRef::DynTraitType(node)
3583 impl AstNode for TypeRef {
3584 fn can_cast(kind: SyntaxKind) -> bool {
3586 PAREN_TYPE | TUPLE_TYPE | NEVER_TYPE | PATH_TYPE | POINTER_TYPE | ARRAY_TYPE
3587 | SLICE_TYPE | REFERENCE_TYPE | PLACEHOLDER_TYPE | FN_POINTER_TYPE | FOR_TYPE
3588 | IMPL_TRAIT_TYPE | DYN_TRAIT_TYPE => true,
3592 fn cast(syntax: SyntaxNode) -> Option<Self> {
3593 let res = match syntax.kind() {
3594 PAREN_TYPE => TypeRef::ParenType(ParenType { syntax }),
3595 TUPLE_TYPE => TypeRef::TupleType(TupleType { syntax }),
3596 NEVER_TYPE => TypeRef::NeverType(NeverType { syntax }),
3597 PATH_TYPE => TypeRef::PathType(PathType { syntax }),
3598 POINTER_TYPE => TypeRef::PointerType(PointerType { syntax }),
3599 ARRAY_TYPE => TypeRef::ArrayType(ArrayType { syntax }),
3600 SLICE_TYPE => TypeRef::SliceType(SliceType { syntax }),
3601 REFERENCE_TYPE => TypeRef::ReferenceType(ReferenceType { syntax }),
3602 PLACEHOLDER_TYPE => TypeRef::PlaceholderType(PlaceholderType { syntax }),
3603 FN_POINTER_TYPE => TypeRef::FnPointerType(FnPointerType { syntax }),
3604 FOR_TYPE => TypeRef::ForType(ForType { syntax }),
3605 IMPL_TRAIT_TYPE => TypeRef::ImplTraitType(ImplTraitType { syntax }),
3606 DYN_TRAIT_TYPE => TypeRef::DynTraitType(DynTraitType { syntax }),
3611 fn syntax(&self) -> &SyntaxNode {
3613 TypeRef::ParenType(it) => &it.syntax,
3614 TypeRef::TupleType(it) => &it.syntax,
3615 TypeRef::NeverType(it) => &it.syntax,
3616 TypeRef::PathType(it) => &it.syntax,
3617 TypeRef::PointerType(it) => &it.syntax,
3618 TypeRef::ArrayType(it) => &it.syntax,
3619 TypeRef::SliceType(it) => &it.syntax,
3620 TypeRef::ReferenceType(it) => &it.syntax,
3621 TypeRef::PlaceholderType(it) => &it.syntax,
3622 TypeRef::FnPointerType(it) => &it.syntax,
3623 TypeRef::ForType(it) => &it.syntax,
3624 TypeRef::ImplTraitType(it) => &it.syntax,
3625 TypeRef::DynTraitType(it) => &it.syntax,
3630 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3631 pub struct UseItem {
3632 pub(crate) syntax: SyntaxNode,
3634 impl AstNode for UseItem {
3635 fn can_cast(kind: SyntaxKind) -> bool {
3641 fn cast(syntax: SyntaxNode) -> Option<Self> {
3642 if Self::can_cast(syntax.kind()) {
3643 Some(Self { syntax })
3648 fn syntax(&self) -> &SyntaxNode {
3652 impl ast::AttrsOwner for UseItem {}
3654 pub fn use_tree(&self) -> Option<UseTree> {
3655 AstChildren::new(&self.syntax).next()
3658 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3659 pub struct UseTree {
3660 pub(crate) syntax: SyntaxNode,
3662 impl AstNode for UseTree {
3663 fn can_cast(kind: SyntaxKind) -> bool {
3669 fn cast(syntax: SyntaxNode) -> Option<Self> {
3670 if Self::can_cast(syntax.kind()) {
3671 Some(Self { syntax })
3676 fn syntax(&self) -> &SyntaxNode {
3681 pub fn path(&self) -> Option<Path> {
3682 AstChildren::new(&self.syntax).next()
3684 pub fn use_tree_list(&self) -> Option<UseTreeList> {
3685 AstChildren::new(&self.syntax).next()
3687 pub fn alias(&self) -> Option<Alias> {
3688 AstChildren::new(&self.syntax).next()
3691 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3692 pub struct UseTreeList {
3693 pub(crate) syntax: SyntaxNode,
3695 impl AstNode for UseTreeList {
3696 fn can_cast(kind: SyntaxKind) -> bool {
3698 USE_TREE_LIST => true,
3702 fn cast(syntax: SyntaxNode) -> Option<Self> {
3703 if Self::can_cast(syntax.kind()) {
3704 Some(Self { syntax })
3709 fn syntax(&self) -> &SyntaxNode {
3714 pub fn use_trees(&self) -> AstChildren<UseTree> {
3715 AstChildren::new(&self.syntax)
3718 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3719 pub struct Visibility {
3720 pub(crate) syntax: SyntaxNode,
3722 impl AstNode for Visibility {
3723 fn can_cast(kind: SyntaxKind) -> bool {
3729 fn cast(syntax: SyntaxNode) -> Option<Self> {
3730 if Self::can_cast(syntax.kind()) {
3731 Some(Self { syntax })
3736 fn syntax(&self) -> &SyntaxNode {
3741 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3742 pub struct WhereClause {
3743 pub(crate) syntax: SyntaxNode,
3745 impl AstNode for WhereClause {
3746 fn can_cast(kind: SyntaxKind) -> bool {
3748 WHERE_CLAUSE => true,
3752 fn cast(syntax: SyntaxNode) -> Option<Self> {
3753 if Self::can_cast(syntax.kind()) {
3754 Some(Self { syntax })
3759 fn syntax(&self) -> &SyntaxNode {
3764 pub fn predicates(&self) -> AstChildren<WherePred> {
3765 AstChildren::new(&self.syntax)
3768 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3769 pub struct WherePred {
3770 pub(crate) syntax: SyntaxNode,
3772 impl AstNode for WherePred {
3773 fn can_cast(kind: SyntaxKind) -> bool {
3779 fn cast(syntax: SyntaxNode) -> Option<Self> {
3780 if Self::can_cast(syntax.kind()) {
3781 Some(Self { syntax })
3786 fn syntax(&self) -> &SyntaxNode {
3790 impl ast::TypeBoundsOwner for WherePred {}
3792 pub fn type_ref(&self) -> Option<TypeRef> {
3793 AstChildren::new(&self.syntax).next()
3796 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
3797 pub struct WhileExpr {
3798 pub(crate) syntax: SyntaxNode,
3800 impl AstNode for WhileExpr {
3801 fn can_cast(kind: SyntaxKind) -> bool {
3807 fn cast(syntax: SyntaxNode) -> Option<Self> {
3808 if Self::can_cast(syntax.kind()) {
3809 Some(Self { syntax })
3814 fn syntax(&self) -> &SyntaxNode {
3818 impl ast::LoopBodyOwner for WhileExpr {}
3820 pub fn condition(&self) -> Option<Condition> {
3821 AstChildren::new(&self.syntax).next()