-// This file is automatically generated based on the file `./generated.rs.tera` when `cargo gen-syntax` is run
-// Do not edit manually
-
-//! This module contains auto-generated Rust AST. Like `SyntaxNode`s, AST nodes
-//! are generic over ownership: `X<'a>` things are `Copy` references, `XNode`
-//! are Arc-based. You can switch between the two variants using `.owned` and
-//! `.borrowed` functions. Most of the code works with borowed mode, and only
-//! this mode has all AST accessors.
-
-#![cfg_attr(rustfmt, rustfmt_skip)]
-
-use rowan::TransparentNewType;
+//! Generated file, do not edit by hand, see `crate/ra_tools/src/codegen`
use crate::{
- SyntaxNode, SyntaxKind::*,
- syntax_node::{RaTypes, TreeArc},
- ast::{self, AstNode},
+ ast::{self, AstChildren, AstNode},
+ SyntaxKind::{self, *},
+ SyntaxNode,
};
-
-// Alias
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Alias {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for Alias {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for Alias {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- ALIAS => Some(Alias::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ ALIAS => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for Alias {
- type Owned = TreeArc<Alias>;
- fn to_owned(&self) -> TreeArc<Alias> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::NameOwner for Alias {}
impl Alias {}
-
-// ArgList
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ArgList {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for ArgList {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for ArgList {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- ARG_LIST => Some(ArgList::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ ARG_LIST => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for ArgList {
- type Owned = TreeArc<ArgList>;
- fn to_owned(&self) -> TreeArc<ArgList> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ArgList {
- pub fn args(&self) -> impl Iterator<Item = &Expr> {
- super::children(self)
+ pub fn args(&self) -> AstChildren<Expr> {
+ AstChildren::new(&self.syntax)
}
}
-
-// ArrayExpr
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ArrayExpr {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for ArrayExpr {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for ArrayExpr {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- ARRAY_EXPR => Some(ArrayExpr::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ ARRAY_EXPR => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for ArrayExpr {
- type Owned = TreeArc<ArrayExpr>;
- fn to_owned(&self) -> TreeArc<ArrayExpr> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ArrayExpr {
- pub fn exprs(&self) -> impl Iterator<Item = &Expr> {
- super::children(self)
+ pub fn exprs(&self) -> AstChildren<Expr> {
+ AstChildren::new(&self.syntax)
}
}
-
-// ArrayType
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ArrayType {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for ArrayType {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for ArrayType {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- ARRAY_TYPE => Some(ArrayType::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ ARRAY_TYPE => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for ArrayType {
- type Owned = TreeArc<ArrayType>;
- fn to_owned(&self) -> TreeArc<ArrayType> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ArrayType {
- pub fn type_ref(&self) -> Option<&TypeRef> {
- super::child_opt(self)
+ pub fn type_ref(&self) -> Option<TypeRef> {
+ AstChildren::new(&self.syntax).next()
}
-
- pub fn expr(&self) -> Option<&Expr> {
- super::child_opt(self)
+ pub fn expr(&self) -> Option<Expr> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// AssocTypeArg
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct AssocTypeArg {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for AssocTypeArg {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for AssocTypeArg {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- ASSOC_TYPE_ARG => Some(AssocTypeArg::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ ASSOC_TYPE_ARG => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for AssocTypeArg {
- type Owned = TreeArc<AssocTypeArg>;
- fn to_owned(&self) -> TreeArc<AssocTypeArg> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl AssocTypeArg {
- pub fn name_ref(&self) -> Option<&NameRef> {
- super::child_opt(self)
+ pub fn name_ref(&self) -> Option<NameRef> {
+ AstChildren::new(&self.syntax).next()
}
-
- pub fn type_ref(&self) -> Option<&TypeRef> {
- super::child_opt(self)
+ pub fn type_ref(&self) -> Option<TypeRef> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// Attr
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Attr {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for Attr {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for Attr {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- ATTR => Some(Attr::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ ATTR => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for Attr {
- type Owned = TreeArc<Attr>;
- fn to_owned(&self) -> TreeArc<Attr> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl Attr {
- pub fn value(&self) -> Option<&TokenTree> {
- super::child_opt(self)
+ pub fn path(&self) -> Option<Path> {
+ AstChildren::new(&self.syntax).next()
+ }
+ pub fn input(&self) -> Option<AttrInput> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// BinExpr
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
-pub struct BinExpr {
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub enum AttrInput {
+ Literal(Literal),
+ TokenTree(TokenTree),
+}
+impl From<Literal> for AttrInput {
+ fn from(node: Literal) -> AttrInput {
+ AttrInput::Literal(node)
+ }
+}
+impl From<TokenTree> for AttrInput {
+ fn from(node: TokenTree) -> AttrInput {
+ AttrInput::TokenTree(node)
+ }
+}
+impl AstNode for AttrInput {
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ LITERAL | TOKEN_TREE => true,
+ _ => false,
+ }
+ }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ let res = match syntax.kind() {
+ LITERAL => AttrInput::Literal(Literal { syntax }),
+ TOKEN_TREE => AttrInput::TokenTree(TokenTree { syntax }),
+ _ => return None,
+ };
+ Some(res)
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ match self {
+ AttrInput::Literal(it) => &it.syntax,
+ AttrInput::TokenTree(it) => &it.syntax,
+ }
+ }
+}
+impl AttrInput {}
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct AwaitExpr {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for BinExpr {
- type Repr = rowan::SyntaxNode<RaTypes>;
+impl AstNode for AwaitExpr {
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ AWAIT_EXPR => true,
+ _ => false,
+ }
+ }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
+}
+impl AwaitExpr {
+ pub fn expr(&self) -> Option<Expr> {
+ AstChildren::new(&self.syntax).next()
+ }
+}
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct BinExpr {
+ pub(crate) syntax: SyntaxNode,
}
-
impl AstNode for BinExpr {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- BIN_EXPR => Some(BinExpr::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ BIN_EXPR => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for BinExpr {
- type Owned = TreeArc<BinExpr>;
- fn to_owned(&self) -> TreeArc<BinExpr> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl BinExpr {}
-
-// BindPat
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct BindPat {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for BindPat {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for BindPat {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- BIND_PAT => Some(BindPat::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ BIND_PAT => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for BindPat {
- type Owned = TreeArc<BindPat>;
- fn to_owned(&self) -> TreeArc<BindPat> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::NameOwner for BindPat {}
impl BindPat {
- pub fn pat(&self) -> Option<&Pat> {
- super::child_opt(self)
+ pub fn pat(&self) -> Option<Pat> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// Block
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Block {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for Block {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for Block {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- BLOCK => Some(Block::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ BLOCK => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for Block {
- type Owned = TreeArc<Block>;
- fn to_owned(&self) -> TreeArc<Block> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::AttrsOwner for Block {}
+impl ast::ModuleItemOwner for Block {}
impl Block {
- pub fn statements(&self) -> impl Iterator<Item = &Stmt> {
- super::children(self)
+ pub fn statements(&self) -> AstChildren<Stmt> {
+ AstChildren::new(&self.syntax)
}
-
- pub fn expr(&self) -> Option<&Expr> {
- super::child_opt(self)
+ pub fn expr(&self) -> Option<Expr> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// BlockExpr
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct BlockExpr {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for BlockExpr {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for BlockExpr {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- BLOCK_EXPR => Some(BlockExpr::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ BLOCK_EXPR => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for BlockExpr {
- type Owned = TreeArc<BlockExpr>;
- fn to_owned(&self) -> TreeArc<BlockExpr> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl BlockExpr {
- pub fn block(&self) -> Option<&Block> {
- super::child_opt(self)
+ pub fn block(&self) -> Option<Block> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// BreakExpr
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
-pub struct BreakExpr {
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct BoxExpr {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for BreakExpr {
- type Repr = rowan::SyntaxNode<RaTypes>;
+impl AstNode for BoxExpr {
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ BOX_EXPR => true,
+ _ => false,
+ }
+ }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-impl AstNode for BreakExpr {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- BREAK_EXPR => Some(BreakExpr::from_repr(syntax.into_repr())),
- _ => None,
+impl BoxExpr {
+ pub fn expr(&self) -> Option<Expr> {
+ AstChildren::new(&self.syntax).next()
+ }
+}
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct BoxPat {
+ pub(crate) syntax: SyntaxNode,
+}
+impl AstNode for BoxPat {
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ BOX_PAT => true,
+ _ => false,
+ }
+ }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-impl ToOwned for BreakExpr {
- type Owned = TreeArc<BreakExpr>;
- fn to_owned(&self) -> TreeArc<BreakExpr> { TreeArc::cast(self.syntax.to_owned()) }
+impl BoxPat {
+ pub fn pat(&self) -> Option<Pat> {
+ AstChildren::new(&self.syntax).next()
+ }
+}
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct BreakExpr {
+ pub(crate) syntax: SyntaxNode,
+}
+impl AstNode for BreakExpr {
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ BREAK_EXPR => true,
+ _ => false,
+ }
+ }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl BreakExpr {
- pub fn expr(&self) -> Option<&Expr> {
- super::child_opt(self)
+ pub fn expr(&self) -> Option<Expr> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// CallExpr
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct CallExpr {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for CallExpr {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for CallExpr {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- CALL_EXPR => Some(CallExpr::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ CALL_EXPR => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for CallExpr {
- type Owned = TreeArc<CallExpr>;
- fn to_owned(&self) -> TreeArc<CallExpr> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::ArgListOwner for CallExpr {}
impl CallExpr {
- pub fn expr(&self) -> Option<&Expr> {
- super::child_opt(self)
+ pub fn expr(&self) -> Option<Expr> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// CastExpr
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct CastExpr {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for CastExpr {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for CastExpr {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- CAST_EXPR => Some(CastExpr::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ CAST_EXPR => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for CastExpr {
- type Owned = TreeArc<CastExpr>;
- fn to_owned(&self) -> TreeArc<CastExpr> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl CastExpr {
- pub fn expr(&self) -> Option<&Expr> {
- super::child_opt(self)
+ pub fn expr(&self) -> Option<Expr> {
+ AstChildren::new(&self.syntax).next()
}
-
- pub fn type_ref(&self) -> Option<&TypeRef> {
- super::child_opt(self)
+ pub fn type_ref(&self) -> Option<TypeRef> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// Condition
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Condition {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for Condition {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for Condition {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- CONDITION => Some(Condition::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ CONDITION => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for Condition {
- type Owned = TreeArc<Condition>;
- fn to_owned(&self) -> TreeArc<Condition> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl Condition {
- pub fn pat(&self) -> Option<&Pat> {
- super::child_opt(self)
+ pub fn pat(&self) -> Option<Pat> {
+ AstChildren::new(&self.syntax).next()
}
-
- pub fn expr(&self) -> Option<&Expr> {
- super::child_opt(self)
+ pub fn expr(&self) -> Option<Expr> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// ConstDef
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ConstDef {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for ConstDef {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for ConstDef {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- CONST_DEF => Some(ConstDef::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ CONST_DEF => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for ConstDef {
- type Owned = TreeArc<ConstDef>;
- fn to_owned(&self) -> TreeArc<ConstDef> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::VisibilityOwner for ConstDef {}
impl ast::NameOwner for ConstDef {}
impl ast::TypeParamsOwner for ConstDef {}
impl ast::AttrsOwner for ConstDef {}
impl ast::DocCommentsOwner for ConstDef {}
impl ast::TypeAscriptionOwner for ConstDef {}
-impl ConstDef {}
-
-// ContinueExpr
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+impl ConstDef {
+ pub fn body(&self) -> Option<Expr> {
+ AstChildren::new(&self.syntax).next()
+ }
+}
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ContinueExpr {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for ContinueExpr {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for ContinueExpr {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- CONTINUE_EXPR => Some(ContinueExpr::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ CONTINUE_EXPR => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for ContinueExpr {
- type Owned = TreeArc<ContinueExpr>;
- fn to_owned(&self) -> TreeArc<ContinueExpr> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ContinueExpr {}
-
-// DynTraitType
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
-pub struct DynTraitType {
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct DotDotPat {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for DynTraitType {
- type Repr = rowan::SyntaxNode<RaTypes>;
+impl AstNode for DotDotPat {
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ DOT_DOT_PAT => true,
+ _ => false,
+ }
+ }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
+}
+impl DotDotPat {}
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct DynTraitType {
+ pub(crate) syntax: SyntaxNode,
}
-
impl AstNode for DynTraitType {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- DYN_TRAIT_TYPE => Some(DynTraitType::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ DYN_TRAIT_TYPE => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for DynTraitType {
- type Owned = TreeArc<DynTraitType>;
- fn to_owned(&self) -> TreeArc<DynTraitType> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::TypeBoundsOwner for DynTraitType {}
impl DynTraitType {}
-
-// EnumDef
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct EnumDef {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for EnumDef {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for EnumDef {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- ENUM_DEF => Some(EnumDef::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ ENUM_DEF => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for EnumDef {
- type Owned = TreeArc<EnumDef>;
- fn to_owned(&self) -> TreeArc<EnumDef> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::VisibilityOwner for EnumDef {}
impl ast::NameOwner for EnumDef {}
impl ast::TypeParamsOwner for EnumDef {}
impl ast::AttrsOwner for EnumDef {}
impl ast::DocCommentsOwner for EnumDef {}
impl EnumDef {
- pub fn variant_list(&self) -> Option<&EnumVariantList> {
- super::child_opt(self)
+ pub fn variant_list(&self) -> Option<EnumVariantList> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// EnumVariant
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct EnumVariant {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for EnumVariant {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for EnumVariant {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- ENUM_VARIANT => Some(EnumVariant::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ ENUM_VARIANT => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for EnumVariant {
- type Owned = TreeArc<EnumVariant>;
- fn to_owned(&self) -> TreeArc<EnumVariant> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::NameOwner for EnumVariant {}
impl ast::DocCommentsOwner for EnumVariant {}
impl ast::AttrsOwner for EnumVariant {}
impl EnumVariant {
- pub fn expr(&self) -> Option<&Expr> {
- super::child_opt(self)
+ pub fn expr(&self) -> Option<Expr> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// EnumVariantList
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct EnumVariantList {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for EnumVariantList {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for EnumVariantList {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- ENUM_VARIANT_LIST => Some(EnumVariantList::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ ENUM_VARIANT_LIST => true,
+ _ => false,
+ }
+ }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-impl ToOwned for EnumVariantList {
- type Owned = TreeArc<EnumVariantList>;
- fn to_owned(&self) -> TreeArc<EnumVariantList> { TreeArc::cast(self.syntax.to_owned()) }
-}
-
-
impl EnumVariantList {
- pub fn variants(&self) -> impl Iterator<Item = &EnumVariant> {
- super::children(self)
+ pub fn variants(&self) -> AstChildren<EnumVariant> {
+ AstChildren::new(&self.syntax)
}
}
-
-// Expr
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
-pub struct Expr {
- pub(crate) syntax: SyntaxNode,
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub enum Expr {
+ TupleExpr(TupleExpr),
+ ArrayExpr(ArrayExpr),
+ ParenExpr(ParenExpr),
+ PathExpr(PathExpr),
+ LambdaExpr(LambdaExpr),
+ IfExpr(IfExpr),
+ LoopExpr(LoopExpr),
+ ForExpr(ForExpr),
+ WhileExpr(WhileExpr),
+ ContinueExpr(ContinueExpr),
+ BreakExpr(BreakExpr),
+ Label(Label),
+ BlockExpr(BlockExpr),
+ ReturnExpr(ReturnExpr),
+ MatchExpr(MatchExpr),
+ RecordLit(RecordLit),
+ CallExpr(CallExpr),
+ IndexExpr(IndexExpr),
+ MethodCallExpr(MethodCallExpr),
+ FieldExpr(FieldExpr),
+ AwaitExpr(AwaitExpr),
+ TryExpr(TryExpr),
+ TryBlockExpr(TryBlockExpr),
+ CastExpr(CastExpr),
+ RefExpr(RefExpr),
+ PrefixExpr(PrefixExpr),
+ RangeExpr(RangeExpr),
+ BinExpr(BinExpr),
+ Literal(Literal),
+ MacroCall(MacroCall),
+ BoxExpr(BoxExpr),
}
-unsafe impl TransparentNewType for Expr {
- type Repr = rowan::SyntaxNode<RaTypes>;
+impl From<TupleExpr> for Expr {
+ fn from(node: TupleExpr) -> Expr {
+ Expr::TupleExpr(node)
+ }
}
-
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-pub enum ExprKind<'a> {
- TupleExpr(&'a TupleExpr),
- ArrayExpr(&'a ArrayExpr),
- ParenExpr(&'a ParenExpr),
- PathExpr(&'a PathExpr),
- LambdaExpr(&'a LambdaExpr),
- IfExpr(&'a IfExpr),
- LoopExpr(&'a LoopExpr),
- ForExpr(&'a ForExpr),
- WhileExpr(&'a WhileExpr),
- ContinueExpr(&'a ContinueExpr),
- BreakExpr(&'a BreakExpr),
- Label(&'a Label),
- BlockExpr(&'a BlockExpr),
- ReturnExpr(&'a ReturnExpr),
- MatchExpr(&'a MatchExpr),
- StructLit(&'a StructLit),
- CallExpr(&'a CallExpr),
- IndexExpr(&'a IndexExpr),
- MethodCallExpr(&'a MethodCallExpr),
- FieldExpr(&'a FieldExpr),
- TryExpr(&'a TryExpr),
- CastExpr(&'a CastExpr),
- RefExpr(&'a RefExpr),
- PrefixExpr(&'a PrefixExpr),
- RangeExpr(&'a RangeExpr),
- BinExpr(&'a BinExpr),
- Literal(&'a Literal),
+impl From<ArrayExpr> for Expr {
+ fn from(node: ArrayExpr) -> Expr {
+ Expr::ArrayExpr(node)
+ }
}
-impl<'a> From<&'a TupleExpr> for &'a Expr {
- fn from(n: &'a TupleExpr) -> &'a Expr {
- Expr::cast(&n.syntax).unwrap()
+impl From<ParenExpr> for Expr {
+ fn from(node: ParenExpr) -> Expr {
+ Expr::ParenExpr(node)
}
}
-impl<'a> From<&'a ArrayExpr> for &'a Expr {
- fn from(n: &'a ArrayExpr) -> &'a Expr {
- Expr::cast(&n.syntax).unwrap()
+impl From<PathExpr> for Expr {
+ fn from(node: PathExpr) -> Expr {
+ Expr::PathExpr(node)
}
}
-impl<'a> From<&'a ParenExpr> for &'a Expr {
- fn from(n: &'a ParenExpr) -> &'a Expr {
- Expr::cast(&n.syntax).unwrap()
+impl From<LambdaExpr> for Expr {
+ fn from(node: LambdaExpr) -> Expr {
+ Expr::LambdaExpr(node)
}
}
-impl<'a> From<&'a PathExpr> for &'a Expr {
- fn from(n: &'a PathExpr) -> &'a Expr {
- Expr::cast(&n.syntax).unwrap()
+impl From<IfExpr> for Expr {
+ fn from(node: IfExpr) -> Expr {
+ Expr::IfExpr(node)
}
}
-impl<'a> From<&'a LambdaExpr> for &'a Expr {
- fn from(n: &'a LambdaExpr) -> &'a Expr {
- Expr::cast(&n.syntax).unwrap()
+impl From<LoopExpr> for Expr {
+ fn from(node: LoopExpr) -> Expr {
+ Expr::LoopExpr(node)
}
}
-impl<'a> From<&'a IfExpr> for &'a Expr {
- fn from(n: &'a IfExpr) -> &'a Expr {
- Expr::cast(&n.syntax).unwrap()
+impl From<ForExpr> for Expr {
+ fn from(node: ForExpr) -> Expr {
+ Expr::ForExpr(node)
}
}
-impl<'a> From<&'a LoopExpr> for &'a Expr {
- fn from(n: &'a LoopExpr) -> &'a Expr {
- Expr::cast(&n.syntax).unwrap()
+impl From<WhileExpr> for Expr {
+ fn from(node: WhileExpr) -> Expr {
+ Expr::WhileExpr(node)
}
}
-impl<'a> From<&'a ForExpr> for &'a Expr {
- fn from(n: &'a ForExpr) -> &'a Expr {
- Expr::cast(&n.syntax).unwrap()
+impl From<ContinueExpr> for Expr {
+ fn from(node: ContinueExpr) -> Expr {
+ Expr::ContinueExpr(node)
}
}
-impl<'a> From<&'a WhileExpr> for &'a Expr {
- fn from(n: &'a WhileExpr) -> &'a Expr {
- Expr::cast(&n.syntax).unwrap()
+impl From<BreakExpr> for Expr {
+ fn from(node: BreakExpr) -> Expr {
+ Expr::BreakExpr(node)
}
}
-impl<'a> From<&'a ContinueExpr> for &'a Expr {
- fn from(n: &'a ContinueExpr) -> &'a Expr {
- Expr::cast(&n.syntax).unwrap()
+impl From<Label> for Expr {
+ fn from(node: Label) -> Expr {
+ Expr::Label(node)
}
}
-impl<'a> From<&'a BreakExpr> for &'a Expr {
- fn from(n: &'a BreakExpr) -> &'a Expr {
- Expr::cast(&n.syntax).unwrap()
+impl From<BlockExpr> for Expr {
+ fn from(node: BlockExpr) -> Expr {
+ Expr::BlockExpr(node)
}
}
-impl<'a> From<&'a Label> for &'a Expr {
- fn from(n: &'a Label) -> &'a Expr {
- Expr::cast(&n.syntax).unwrap()
+impl From<ReturnExpr> for Expr {
+ fn from(node: ReturnExpr) -> Expr {
+ Expr::ReturnExpr(node)
}
}
-impl<'a> From<&'a BlockExpr> for &'a Expr {
- fn from(n: &'a BlockExpr) -> &'a Expr {
- Expr::cast(&n.syntax).unwrap()
+impl From<MatchExpr> for Expr {
+ fn from(node: MatchExpr) -> Expr {
+ Expr::MatchExpr(node)
}
}
-impl<'a> From<&'a ReturnExpr> for &'a Expr {
- fn from(n: &'a ReturnExpr) -> &'a Expr {
- Expr::cast(&n.syntax).unwrap()
+impl From<RecordLit> for Expr {
+ fn from(node: RecordLit) -> Expr {
+ Expr::RecordLit(node)
}
}
-impl<'a> From<&'a MatchExpr> for &'a Expr {
- fn from(n: &'a MatchExpr) -> &'a Expr {
- Expr::cast(&n.syntax).unwrap()
+impl From<CallExpr> for Expr {
+ fn from(node: CallExpr) -> Expr {
+ Expr::CallExpr(node)
}
}
-impl<'a> From<&'a StructLit> for &'a Expr {
- fn from(n: &'a StructLit) -> &'a Expr {
- Expr::cast(&n.syntax).unwrap()
+impl From<IndexExpr> for Expr {
+ fn from(node: IndexExpr) -> Expr {
+ Expr::IndexExpr(node)
}
}
-impl<'a> From<&'a CallExpr> for &'a Expr {
- fn from(n: &'a CallExpr) -> &'a Expr {
- Expr::cast(&n.syntax).unwrap()
+impl From<MethodCallExpr> for Expr {
+ fn from(node: MethodCallExpr) -> Expr {
+ Expr::MethodCallExpr(node)
}
}
-impl<'a> From<&'a IndexExpr> for &'a Expr {
- fn from(n: &'a IndexExpr) -> &'a Expr {
- Expr::cast(&n.syntax).unwrap()
+impl From<FieldExpr> for Expr {
+ fn from(node: FieldExpr) -> Expr {
+ Expr::FieldExpr(node)
}
}
-impl<'a> From<&'a MethodCallExpr> for &'a Expr {
- fn from(n: &'a MethodCallExpr) -> &'a Expr {
- Expr::cast(&n.syntax).unwrap()
+impl From<AwaitExpr> for Expr {
+ fn from(node: AwaitExpr) -> Expr {
+ Expr::AwaitExpr(node)
}
}
-impl<'a> From<&'a FieldExpr> for &'a Expr {
- fn from(n: &'a FieldExpr) -> &'a Expr {
- Expr::cast(&n.syntax).unwrap()
+impl From<TryExpr> for Expr {
+ fn from(node: TryExpr) -> Expr {
+ Expr::TryExpr(node)
}
}
-impl<'a> From<&'a TryExpr> for &'a Expr {
- fn from(n: &'a TryExpr) -> &'a Expr {
- Expr::cast(&n.syntax).unwrap()
+impl From<TryBlockExpr> for Expr {
+ fn from(node: TryBlockExpr) -> Expr {
+ Expr::TryBlockExpr(node)
}
}
-impl<'a> From<&'a CastExpr> for &'a Expr {
- fn from(n: &'a CastExpr) -> &'a Expr {
- Expr::cast(&n.syntax).unwrap()
+impl From<CastExpr> for Expr {
+ fn from(node: CastExpr) -> Expr {
+ Expr::CastExpr(node)
}
}
-impl<'a> From<&'a RefExpr> for &'a Expr {
- fn from(n: &'a RefExpr) -> &'a Expr {
- Expr::cast(&n.syntax).unwrap()
+impl From<RefExpr> for Expr {
+ fn from(node: RefExpr) -> Expr {
+ Expr::RefExpr(node)
}
}
-impl<'a> From<&'a PrefixExpr> for &'a Expr {
- fn from(n: &'a PrefixExpr) -> &'a Expr {
- Expr::cast(&n.syntax).unwrap()
+impl From<PrefixExpr> for Expr {
+ fn from(node: PrefixExpr) -> Expr {
+ Expr::PrefixExpr(node)
}
}
-impl<'a> From<&'a RangeExpr> for &'a Expr {
- fn from(n: &'a RangeExpr) -> &'a Expr {
- Expr::cast(&n.syntax).unwrap()
+impl From<RangeExpr> for Expr {
+ fn from(node: RangeExpr) -> Expr {
+ Expr::RangeExpr(node)
}
}
-impl<'a> From<&'a BinExpr> for &'a Expr {
- fn from(n: &'a BinExpr) -> &'a Expr {
- Expr::cast(&n.syntax).unwrap()
+impl From<BinExpr> for Expr {
+ fn from(node: BinExpr) -> Expr {
+ Expr::BinExpr(node)
}
}
-impl<'a> From<&'a Literal> for &'a Expr {
- fn from(n: &'a Literal) -> &'a Expr {
- Expr::cast(&n.syntax).unwrap()
+impl From<Literal> for Expr {
+ fn from(node: Literal) -> Expr {
+ Expr::Literal(node)
}
}
-
-
-impl AstNode for Expr {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- | TUPLE_EXPR
- | ARRAY_EXPR
- | PAREN_EXPR
- | PATH_EXPR
- | LAMBDA_EXPR
- | IF_EXPR
- | LOOP_EXPR
- | FOR_EXPR
- | WHILE_EXPR
- | CONTINUE_EXPR
- | BREAK_EXPR
- | LABEL
- | BLOCK_EXPR
- | RETURN_EXPR
- | MATCH_EXPR
- | STRUCT_LIT
- | CALL_EXPR
- | INDEX_EXPR
- | METHOD_CALL_EXPR
- | FIELD_EXPR
- | TRY_EXPR
- | CAST_EXPR
- | REF_EXPR
- | PREFIX_EXPR
- | RANGE_EXPR
- | BIN_EXPR
- | LITERAL => Some(Expr::from_repr(syntax.into_repr())),
- _ => None,
- }
- }
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
+impl From<MacroCall> for Expr {
+ fn from(node: MacroCall) -> Expr {
+ Expr::MacroCall(node)
+ }
}
-
-impl ToOwned for Expr {
- type Owned = TreeArc<Expr>;
- fn to_owned(&self) -> TreeArc<Expr> { TreeArc::cast(self.syntax.to_owned()) }
+impl From<BoxExpr> for Expr {
+ fn from(node: BoxExpr) -> Expr {
+ Expr::BoxExpr(node)
+ }
}
-
-impl Expr {
- pub fn kind(&self) -> ExprKind {
- match self.syntax.kind() {
- TUPLE_EXPR => ExprKind::TupleExpr(TupleExpr::cast(&self.syntax).unwrap()),
- ARRAY_EXPR => ExprKind::ArrayExpr(ArrayExpr::cast(&self.syntax).unwrap()),
- PAREN_EXPR => ExprKind::ParenExpr(ParenExpr::cast(&self.syntax).unwrap()),
- PATH_EXPR => ExprKind::PathExpr(PathExpr::cast(&self.syntax).unwrap()),
- LAMBDA_EXPR => ExprKind::LambdaExpr(LambdaExpr::cast(&self.syntax).unwrap()),
- IF_EXPR => ExprKind::IfExpr(IfExpr::cast(&self.syntax).unwrap()),
- LOOP_EXPR => ExprKind::LoopExpr(LoopExpr::cast(&self.syntax).unwrap()),
- FOR_EXPR => ExprKind::ForExpr(ForExpr::cast(&self.syntax).unwrap()),
- WHILE_EXPR => ExprKind::WhileExpr(WhileExpr::cast(&self.syntax).unwrap()),
- CONTINUE_EXPR => ExprKind::ContinueExpr(ContinueExpr::cast(&self.syntax).unwrap()),
- BREAK_EXPR => ExprKind::BreakExpr(BreakExpr::cast(&self.syntax).unwrap()),
- LABEL => ExprKind::Label(Label::cast(&self.syntax).unwrap()),
- BLOCK_EXPR => ExprKind::BlockExpr(BlockExpr::cast(&self.syntax).unwrap()),
- RETURN_EXPR => ExprKind::ReturnExpr(ReturnExpr::cast(&self.syntax).unwrap()),
- MATCH_EXPR => ExprKind::MatchExpr(MatchExpr::cast(&self.syntax).unwrap()),
- STRUCT_LIT => ExprKind::StructLit(StructLit::cast(&self.syntax).unwrap()),
- CALL_EXPR => ExprKind::CallExpr(CallExpr::cast(&self.syntax).unwrap()),
- INDEX_EXPR => ExprKind::IndexExpr(IndexExpr::cast(&self.syntax).unwrap()),
- METHOD_CALL_EXPR => ExprKind::MethodCallExpr(MethodCallExpr::cast(&self.syntax).unwrap()),
- FIELD_EXPR => ExprKind::FieldExpr(FieldExpr::cast(&self.syntax).unwrap()),
- TRY_EXPR => ExprKind::TryExpr(TryExpr::cast(&self.syntax).unwrap()),
- CAST_EXPR => ExprKind::CastExpr(CastExpr::cast(&self.syntax).unwrap()),
- REF_EXPR => ExprKind::RefExpr(RefExpr::cast(&self.syntax).unwrap()),
- PREFIX_EXPR => ExprKind::PrefixExpr(PrefixExpr::cast(&self.syntax).unwrap()),
- RANGE_EXPR => ExprKind::RangeExpr(RangeExpr::cast(&self.syntax).unwrap()),
- BIN_EXPR => ExprKind::BinExpr(BinExpr::cast(&self.syntax).unwrap()),
- LITERAL => ExprKind::Literal(Literal::cast(&self.syntax).unwrap()),
- _ => unreachable!(),
+impl AstNode for Expr {
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR
+ | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL
+ | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | RECORD_LIT | CALL_EXPR | INDEX_EXPR
+ | METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | TRY_BLOCK_EXPR
+ | CAST_EXPR | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL
+ | BOX_EXPR => true,
+ _ => false,
+ }
+ }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ let res = match syntax.kind() {
+ TUPLE_EXPR => Expr::TupleExpr(TupleExpr { syntax }),
+ ARRAY_EXPR => Expr::ArrayExpr(ArrayExpr { syntax }),
+ PAREN_EXPR => Expr::ParenExpr(ParenExpr { syntax }),
+ PATH_EXPR => Expr::PathExpr(PathExpr { syntax }),
+ LAMBDA_EXPR => Expr::LambdaExpr(LambdaExpr { syntax }),
+ IF_EXPR => Expr::IfExpr(IfExpr { syntax }),
+ LOOP_EXPR => Expr::LoopExpr(LoopExpr { syntax }),
+ FOR_EXPR => Expr::ForExpr(ForExpr { syntax }),
+ WHILE_EXPR => Expr::WhileExpr(WhileExpr { syntax }),
+ CONTINUE_EXPR => Expr::ContinueExpr(ContinueExpr { syntax }),
+ BREAK_EXPR => Expr::BreakExpr(BreakExpr { syntax }),
+ LABEL => Expr::Label(Label { syntax }),
+ BLOCK_EXPR => Expr::BlockExpr(BlockExpr { syntax }),
+ RETURN_EXPR => Expr::ReturnExpr(ReturnExpr { syntax }),
+ MATCH_EXPR => Expr::MatchExpr(MatchExpr { syntax }),
+ RECORD_LIT => Expr::RecordLit(RecordLit { syntax }),
+ CALL_EXPR => Expr::CallExpr(CallExpr { syntax }),
+ INDEX_EXPR => Expr::IndexExpr(IndexExpr { syntax }),
+ METHOD_CALL_EXPR => Expr::MethodCallExpr(MethodCallExpr { syntax }),
+ FIELD_EXPR => Expr::FieldExpr(FieldExpr { syntax }),
+ AWAIT_EXPR => Expr::AwaitExpr(AwaitExpr { syntax }),
+ TRY_EXPR => Expr::TryExpr(TryExpr { syntax }),
+ TRY_BLOCK_EXPR => Expr::TryBlockExpr(TryBlockExpr { syntax }),
+ CAST_EXPR => Expr::CastExpr(CastExpr { syntax }),
+ REF_EXPR => Expr::RefExpr(RefExpr { syntax }),
+ PREFIX_EXPR => Expr::PrefixExpr(PrefixExpr { syntax }),
+ RANGE_EXPR => Expr::RangeExpr(RangeExpr { syntax }),
+ BIN_EXPR => Expr::BinExpr(BinExpr { syntax }),
+ LITERAL => Expr::Literal(Literal { syntax }),
+ MACRO_CALL => Expr::MacroCall(MacroCall { syntax }),
+ BOX_EXPR => Expr::BoxExpr(BoxExpr { syntax }),
+ _ => return None,
+ };
+ Some(res)
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ match self {
+ Expr::TupleExpr(it) => &it.syntax,
+ Expr::ArrayExpr(it) => &it.syntax,
+ Expr::ParenExpr(it) => &it.syntax,
+ Expr::PathExpr(it) => &it.syntax,
+ Expr::LambdaExpr(it) => &it.syntax,
+ Expr::IfExpr(it) => &it.syntax,
+ Expr::LoopExpr(it) => &it.syntax,
+ Expr::ForExpr(it) => &it.syntax,
+ Expr::WhileExpr(it) => &it.syntax,
+ Expr::ContinueExpr(it) => &it.syntax,
+ Expr::BreakExpr(it) => &it.syntax,
+ Expr::Label(it) => &it.syntax,
+ Expr::BlockExpr(it) => &it.syntax,
+ Expr::ReturnExpr(it) => &it.syntax,
+ Expr::MatchExpr(it) => &it.syntax,
+ Expr::RecordLit(it) => &it.syntax,
+ Expr::CallExpr(it) => &it.syntax,
+ Expr::IndexExpr(it) => &it.syntax,
+ Expr::MethodCallExpr(it) => &it.syntax,
+ Expr::FieldExpr(it) => &it.syntax,
+ Expr::AwaitExpr(it) => &it.syntax,
+ Expr::TryExpr(it) => &it.syntax,
+ Expr::TryBlockExpr(it) => &it.syntax,
+ Expr::CastExpr(it) => &it.syntax,
+ Expr::RefExpr(it) => &it.syntax,
+ Expr::PrefixExpr(it) => &it.syntax,
+ Expr::RangeExpr(it) => &it.syntax,
+ Expr::BinExpr(it) => &it.syntax,
+ Expr::Literal(it) => &it.syntax,
+ Expr::MacroCall(it) => &it.syntax,
+ Expr::BoxExpr(it) => &it.syntax,
}
}
}
-
impl Expr {}
-
-// ExprStmt
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ExprStmt {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for ExprStmt {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for ExprStmt {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- EXPR_STMT => Some(ExprStmt::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ EXPR_STMT => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for ExprStmt {
- type Owned = TreeArc<ExprStmt>;
- fn to_owned(&self) -> TreeArc<ExprStmt> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ExprStmt {
- pub fn expr(&self) -> Option<&Expr> {
- super::child_opt(self)
+ pub fn expr(&self) -> Option<Expr> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// ExternCrateItem
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ExternCrateItem {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for ExternCrateItem {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for ExternCrateItem {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- EXTERN_CRATE_ITEM => Some(ExternCrateItem::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ EXTERN_CRATE_ITEM => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for ExternCrateItem {
- type Owned = TreeArc<ExternCrateItem>;
- fn to_owned(&self) -> TreeArc<ExternCrateItem> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
+impl ast::AttrsOwner for ExternCrateItem {}
impl ExternCrateItem {
- pub fn name_ref(&self) -> Option<&NameRef> {
- super::child_opt(self)
+ pub fn name_ref(&self) -> Option<NameRef> {
+ AstChildren::new(&self.syntax).next()
}
-
- pub fn alias(&self) -> Option<&Alias> {
- super::child_opt(self)
+ pub fn alias(&self) -> Option<Alias> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// FieldExpr
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct FieldExpr {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for FieldExpr {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for FieldExpr {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- FIELD_EXPR => Some(FieldExpr::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ FIELD_EXPR => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for FieldExpr {
- type Owned = TreeArc<FieldExpr>;
- fn to_owned(&self) -> TreeArc<FieldExpr> { TreeArc::cast(self.syntax.to_owned()) }
-}
-
-
-impl FieldExpr {
- pub fn expr(&self) -> Option<&Expr> {
- super::child_opt(self)
- }
-
- pub fn name_ref(&self) -> Option<&NameRef> {
- super::child_opt(self)
- }
-}
-
-// FieldPat
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
-pub struct FieldPat {
- pub(crate) syntax: SyntaxNode,
-}
-unsafe impl TransparentNewType for FieldPat {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
-impl AstNode for FieldPat {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- FIELD_PAT => Some(FieldPat::from_repr(syntax.into_repr())),
- _ => None,
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for FieldPat {
- type Owned = TreeArc<FieldPat>;
- fn to_owned(&self) -> TreeArc<FieldPat> { TreeArc::cast(self.syntax.to_owned()) }
-}
-
-
-impl ast::NameOwner for FieldPat {}
-impl FieldPat {
- pub fn pat(&self) -> Option<&Pat> {
- super::child_opt(self)
- }
-}
-
-// FieldPatList
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
-pub struct FieldPatList {
- pub(crate) syntax: SyntaxNode,
-}
-unsafe impl TransparentNewType for FieldPatList {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
-impl AstNode for FieldPatList {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- FIELD_PAT_LIST => Some(FieldPatList::from_repr(syntax.into_repr())),
- _ => None,
- }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for FieldPatList {
- type Owned = TreeArc<FieldPatList>;
- fn to_owned(&self) -> TreeArc<FieldPatList> { TreeArc::cast(self.syntax.to_owned()) }
}
-
-
-impl FieldPatList {
- pub fn field_pats(&self) -> impl Iterator<Item = &FieldPat> {
- super::children(self)
+impl FieldExpr {
+ pub fn expr(&self) -> Option<Expr> {
+ AstChildren::new(&self.syntax).next()
}
-
- pub fn bind_pats(&self) -> impl Iterator<Item = &BindPat> {
- super::children(self)
+ pub fn name_ref(&self) -> Option<NameRef> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// FnDef
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct FnDef {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for FnDef {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for FnDef {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- FN_DEF => Some(FnDef::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ FN_DEF => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for FnDef {
- type Owned = TreeArc<FnDef>;
- fn to_owned(&self) -> TreeArc<FnDef> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::VisibilityOwner for FnDef {}
impl ast::NameOwner for FnDef {}
impl ast::TypeParamsOwner for FnDef {}
impl ast::AttrsOwner for FnDef {}
impl ast::DocCommentsOwner for FnDef {}
impl FnDef {
- pub fn param_list(&self) -> Option<&ParamList> {
- super::child_opt(self)
+ pub fn param_list(&self) -> Option<ParamList> {
+ AstChildren::new(&self.syntax).next()
}
-
- pub fn body(&self) -> Option<&Block> {
- super::child_opt(self)
+ pub fn body(&self) -> Option<BlockExpr> {
+ AstChildren::new(&self.syntax).next()
}
-
- pub fn ret_type(&self) -> Option<&RetType> {
- super::child_opt(self)
+ pub fn ret_type(&self) -> Option<RetType> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// FnPointerType
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct FnPointerType {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for FnPointerType {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for FnPointerType {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- FN_POINTER_TYPE => Some(FnPointerType::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ FN_POINTER_TYPE => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for FnPointerType {
- type Owned = TreeArc<FnPointerType>;
- fn to_owned(&self) -> TreeArc<FnPointerType> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl FnPointerType {
- pub fn param_list(&self) -> Option<&ParamList> {
- super::child_opt(self)
+ pub fn param_list(&self) -> Option<ParamList> {
+ AstChildren::new(&self.syntax).next()
}
-
- pub fn ret_type(&self) -> Option<&RetType> {
- super::child_opt(self)
+ pub fn ret_type(&self) -> Option<RetType> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// ForExpr
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ForExpr {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for ForExpr {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for ForExpr {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- FOR_EXPR => Some(ForExpr::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ FOR_EXPR => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for ForExpr {
- type Owned = TreeArc<ForExpr>;
- fn to_owned(&self) -> TreeArc<ForExpr> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::LoopBodyOwner for ForExpr {}
impl ForExpr {
- pub fn pat(&self) -> Option<&Pat> {
- super::child_opt(self)
+ pub fn pat(&self) -> Option<Pat> {
+ AstChildren::new(&self.syntax).next()
}
-
- pub fn iterable(&self) -> Option<&Expr> {
- super::child_opt(self)
+ pub fn iterable(&self) -> Option<Expr> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// ForType
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ForType {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for ForType {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for ForType {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- FOR_TYPE => Some(ForType::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ FOR_TYPE => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for ForType {
- type Owned = TreeArc<ForType>;
- fn to_owned(&self) -> TreeArc<ForType> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ForType {
- pub fn type_ref(&self) -> Option<&TypeRef> {
- super::child_opt(self)
+ pub fn type_ref(&self) -> Option<TypeRef> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// IfExpr
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct IfExpr {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for IfExpr {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for IfExpr {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- IF_EXPR => Some(IfExpr::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ IF_EXPR => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for IfExpr {
- type Owned = TreeArc<IfExpr>;
- fn to_owned(&self) -> TreeArc<IfExpr> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl IfExpr {
- pub fn condition(&self) -> Option<&Condition> {
- super::child_opt(self)
+ pub fn condition(&self) -> Option<Condition> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// ImplBlock
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ImplBlock {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for ImplBlock {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for ImplBlock {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- IMPL_BLOCK => Some(ImplBlock::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ IMPL_BLOCK => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for ImplBlock {
- type Owned = TreeArc<ImplBlock>;
- fn to_owned(&self) -> TreeArc<ImplBlock> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::TypeParamsOwner for ImplBlock {}
+impl ast::AttrsOwner for ImplBlock {}
impl ImplBlock {
- pub fn item_list(&self) -> Option<&ItemList> {
- super::child_opt(self)
+ pub fn item_list(&self) -> Option<ItemList> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// ImplItem
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
-pub struct ImplItem {
- pub(crate) syntax: SyntaxNode,
-}
-unsafe impl TransparentNewType for ImplItem {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-pub enum ImplItemKind<'a> {
- FnDef(&'a FnDef),
- TypeAliasDef(&'a TypeAliasDef),
- ConstDef(&'a ConstDef),
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub enum ImplItem {
+ FnDef(FnDef),
+ TypeAliasDef(TypeAliasDef),
+ ConstDef(ConstDef),
}
-impl<'a> From<&'a FnDef> for &'a ImplItem {
- fn from(n: &'a FnDef) -> &'a ImplItem {
- ImplItem::cast(&n.syntax).unwrap()
+impl From<FnDef> for ImplItem {
+ fn from(node: FnDef) -> ImplItem {
+ ImplItem::FnDef(node)
}
}
-impl<'a> From<&'a TypeAliasDef> for &'a ImplItem {
- fn from(n: &'a TypeAliasDef) -> &'a ImplItem {
- ImplItem::cast(&n.syntax).unwrap()
+impl From<TypeAliasDef> for ImplItem {
+ fn from(node: TypeAliasDef) -> ImplItem {
+ ImplItem::TypeAliasDef(node)
}
}
-impl<'a> From<&'a ConstDef> for &'a ImplItem {
- fn from(n: &'a ConstDef) -> &'a ImplItem {
- ImplItem::cast(&n.syntax).unwrap()
+impl From<ConstDef> for ImplItem {
+ fn from(node: ConstDef) -> ImplItem {
+ ImplItem::ConstDef(node)
}
}
-
-
impl AstNode for ImplItem {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- | FN_DEF
- | TYPE_ALIAS_DEF
- | CONST_DEF => Some(ImplItem::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for ImplItem {
- type Owned = TreeArc<ImplItem>;
- fn to_owned(&self) -> TreeArc<ImplItem> { TreeArc::cast(self.syntax.to_owned()) }
-}
-
-impl ImplItem {
- pub fn kind(&self) -> ImplItemKind {
- match self.syntax.kind() {
- FN_DEF => ImplItemKind::FnDef(FnDef::cast(&self.syntax).unwrap()),
- TYPE_ALIAS_DEF => ImplItemKind::TypeAliasDef(TypeAliasDef::cast(&self.syntax).unwrap()),
- CONST_DEF => ImplItemKind::ConstDef(ConstDef::cast(&self.syntax).unwrap()),
- _ => unreachable!(),
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ let res = match syntax.kind() {
+ FN_DEF => ImplItem::FnDef(FnDef { syntax }),
+ TYPE_ALIAS_DEF => ImplItem::TypeAliasDef(TypeAliasDef { syntax }),
+ CONST_DEF => ImplItem::ConstDef(ConstDef { syntax }),
+ _ => return None,
+ };
+ Some(res)
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ match self {
+ ImplItem::FnDef(it) => &it.syntax,
+ ImplItem::TypeAliasDef(it) => &it.syntax,
+ ImplItem::ConstDef(it) => &it.syntax,
}
}
}
-
+impl ast::AttrsOwner for ImplItem {}
impl ImplItem {}
-
-// ImplTraitType
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ImplTraitType {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for ImplTraitType {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for ImplTraitType {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- IMPL_TRAIT_TYPE => Some(ImplTraitType::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ IMPL_TRAIT_TYPE => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for ImplTraitType {
- type Owned = TreeArc<ImplTraitType>;
- fn to_owned(&self) -> TreeArc<ImplTraitType> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::TypeBoundsOwner for ImplTraitType {}
impl ImplTraitType {}
-
-// IndexExpr
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct IndexExpr {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for IndexExpr {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for IndexExpr {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- INDEX_EXPR => Some(IndexExpr::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ INDEX_EXPR => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for IndexExpr {
- type Owned = TreeArc<IndexExpr>;
- fn to_owned(&self) -> TreeArc<IndexExpr> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl IndexExpr {}
-
-// ItemList
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ItemList {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for ItemList {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for ItemList {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- ITEM_LIST => Some(ItemList::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ ITEM_LIST => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for ItemList {
- type Owned = TreeArc<ItemList>;
- fn to_owned(&self) -> TreeArc<ItemList> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::FnDefOwner for ItemList {}
impl ast::ModuleItemOwner for ItemList {}
impl ItemList {
- pub fn impl_items(&self) -> impl Iterator<Item = &ImplItem> {
- super::children(self)
+ pub fn impl_items(&self) -> AstChildren<ImplItem> {
+ AstChildren::new(&self.syntax)
}
}
-
-// Label
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Label {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for Label {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for Label {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- LABEL => Some(Label::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ LABEL => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for Label {
- type Owned = TreeArc<Label>;
- fn to_owned(&self) -> TreeArc<Label> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl Label {}
-
-// LambdaExpr
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct LambdaExpr {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for LambdaExpr {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for LambdaExpr {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- LAMBDA_EXPR => Some(LambdaExpr::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ LAMBDA_EXPR => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for LambdaExpr {
- type Owned = TreeArc<LambdaExpr>;
- fn to_owned(&self) -> TreeArc<LambdaExpr> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl LambdaExpr {
- pub fn param_list(&self) -> Option<&ParamList> {
- super::child_opt(self)
+ pub fn param_list(&self) -> Option<ParamList> {
+ AstChildren::new(&self.syntax).next()
}
-
- pub fn body(&self) -> Option<&Expr> {
- super::child_opt(self)
+ pub fn body(&self) -> Option<Expr> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// LetStmt
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct LetStmt {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for LetStmt {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for LetStmt {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- LET_STMT => Some(LetStmt::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ LET_STMT => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for LetStmt {
- type Owned = TreeArc<LetStmt>;
- fn to_owned(&self) -> TreeArc<LetStmt> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::TypeAscriptionOwner for LetStmt {}
impl LetStmt {
- pub fn pat(&self) -> Option<&Pat> {
- super::child_opt(self)
+ pub fn pat(&self) -> Option<Pat> {
+ AstChildren::new(&self.syntax).next()
}
-
- pub fn initializer(&self) -> Option<&Expr> {
- super::child_opt(self)
+ pub fn initializer(&self) -> Option<Expr> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// LifetimeArg
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct LifetimeArg {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for LifetimeArg {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for LifetimeArg {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- LIFETIME_ARG => Some(LifetimeArg::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ LIFETIME_ARG => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for LifetimeArg {
- type Owned = TreeArc<LifetimeArg>;
- fn to_owned(&self) -> TreeArc<LifetimeArg> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl LifetimeArg {}
-
-// LifetimeParam
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct LifetimeParam {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for LifetimeParam {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for LifetimeParam {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- LIFETIME_PARAM => Some(LifetimeParam::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ LIFETIME_PARAM => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for LifetimeParam {
- type Owned = TreeArc<LifetimeParam>;
- fn to_owned(&self) -> TreeArc<LifetimeParam> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::AttrsOwner for LifetimeParam {}
impl LifetimeParam {}
-
-// Literal
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Literal {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for Literal {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for Literal {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- LITERAL => Some(Literal::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ LITERAL => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for Literal {
- type Owned = TreeArc<Literal>;
- fn to_owned(&self) -> TreeArc<Literal> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl Literal {}
-
-// LiteralPat
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct LiteralPat {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for LiteralPat {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for LiteralPat {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- LITERAL_PAT => Some(LiteralPat::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ LITERAL_PAT => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for LiteralPat {
- type Owned = TreeArc<LiteralPat>;
- fn to_owned(&self) -> TreeArc<LiteralPat> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl LiteralPat {
- pub fn literal(&self) -> Option<&Literal> {
- super::child_opt(self)
+ pub fn literal(&self) -> Option<Literal> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// LoopExpr
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct LoopExpr {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for LoopExpr {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for LoopExpr {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- LOOP_EXPR => Some(LoopExpr::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ LOOP_EXPR => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for LoopExpr {
- type Owned = TreeArc<LoopExpr>;
- fn to_owned(&self) -> TreeArc<LoopExpr> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::LoopBodyOwner for LoopExpr {}
impl LoopExpr {}
-
-// MacroCall
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct MacroCall {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for MacroCall {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for MacroCall {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- MACRO_CALL => Some(MacroCall::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ MACRO_CALL => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for MacroCall {
- type Owned = TreeArc<MacroCall>;
- fn to_owned(&self) -> TreeArc<MacroCall> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::NameOwner for MacroCall {}
impl ast::AttrsOwner for MacroCall {}
+impl ast::DocCommentsOwner for MacroCall {}
impl MacroCall {
- pub fn token_tree(&self) -> Option<&TokenTree> {
- super::child_opt(self)
+ pub fn token_tree(&self) -> Option<TokenTree> {
+ AstChildren::new(&self.syntax).next()
}
-
- pub fn path(&self) -> Option<&Path> {
- super::child_opt(self)
+ pub fn path(&self) -> Option<Path> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// MatchArm
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
-pub struct MatchArm {
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct MacroItems {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for MatchArm {
- type Repr = rowan::SyntaxNode<RaTypes>;
+impl AstNode for MacroItems {
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ MACRO_ITEMS => true,
+ _ => false,
+ }
+ }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
+}
+impl ast::ModuleItemOwner for MacroItems {}
+impl ast::FnDefOwner for MacroItems {}
+impl MacroItems {}
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct MacroStmts {
+ pub(crate) syntax: SyntaxNode,
}
-
-impl AstNode for MatchArm {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- MATCH_ARM => Some(MatchArm::from_repr(syntax.into_repr())),
- _ => None,
+impl AstNode for MacroStmts {
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ MACRO_STMTS => true,
+ _ => false,
+ }
+ }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-impl ToOwned for MatchArm {
- type Owned = TreeArc<MatchArm>;
- fn to_owned(&self) -> TreeArc<MatchArm> { TreeArc::cast(self.syntax.to_owned()) }
+impl MacroStmts {
+ pub fn statements(&self) -> AstChildren<Stmt> {
+ AstChildren::new(&self.syntax)
+ }
+ pub fn expr(&self) -> Option<Expr> {
+ AstChildren::new(&self.syntax).next()
+ }
+}
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct MatchArm {
+ pub(crate) syntax: SyntaxNode,
+}
+impl AstNode for MatchArm {
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ MATCH_ARM => true,
+ _ => false,
+ }
+ }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::AttrsOwner for MatchArm {}
impl MatchArm {
- pub fn pats(&self) -> impl Iterator<Item = &Pat> {
- super::children(self)
+ pub fn pats(&self) -> AstChildren<Pat> {
+ AstChildren::new(&self.syntax)
}
-
- pub fn guard(&self) -> Option<&MatchGuard> {
- super::child_opt(self)
+ pub fn guard(&self) -> Option<MatchGuard> {
+ AstChildren::new(&self.syntax).next()
}
-
- pub fn expr(&self) -> Option<&Expr> {
- super::child_opt(self)
+ pub fn expr(&self) -> Option<Expr> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// MatchArmList
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct MatchArmList {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for MatchArmList {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for MatchArmList {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- MATCH_ARM_LIST => Some(MatchArmList::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ MATCH_ARM_LIST => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for MatchArmList {
- type Owned = TreeArc<MatchArmList>;
- fn to_owned(&self) -> TreeArc<MatchArmList> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::AttrsOwner for MatchArmList {}
impl MatchArmList {
- pub fn arms(&self) -> impl Iterator<Item = &MatchArm> {
- super::children(self)
+ pub fn arms(&self) -> AstChildren<MatchArm> {
+ AstChildren::new(&self.syntax)
}
}
-
-// MatchExpr
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct MatchExpr {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for MatchExpr {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for MatchExpr {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- MATCH_EXPR => Some(MatchExpr::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ MATCH_EXPR => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for MatchExpr {
- type Owned = TreeArc<MatchExpr>;
- fn to_owned(&self) -> TreeArc<MatchExpr> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl MatchExpr {
- pub fn expr(&self) -> Option<&Expr> {
- super::child_opt(self)
+ pub fn expr(&self) -> Option<Expr> {
+ AstChildren::new(&self.syntax).next()
}
-
- pub fn match_arm_list(&self) -> Option<&MatchArmList> {
- super::child_opt(self)
+ pub fn match_arm_list(&self) -> Option<MatchArmList> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// MatchGuard
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct MatchGuard {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for MatchGuard {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for MatchGuard {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- MATCH_GUARD => Some(MatchGuard::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ MATCH_GUARD => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for MatchGuard {
- type Owned = TreeArc<MatchGuard>;
- fn to_owned(&self) -> TreeArc<MatchGuard> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl MatchGuard {
- pub fn expr(&self) -> Option<&Expr> {
- super::child_opt(self)
+ pub fn expr(&self) -> Option<Expr> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// MethodCallExpr
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct MethodCallExpr {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for MethodCallExpr {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for MethodCallExpr {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- METHOD_CALL_EXPR => Some(MethodCallExpr::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ METHOD_CALL_EXPR => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for MethodCallExpr {
- type Owned = TreeArc<MethodCallExpr>;
- fn to_owned(&self) -> TreeArc<MethodCallExpr> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::ArgListOwner for MethodCallExpr {}
impl MethodCallExpr {
- pub fn expr(&self) -> Option<&Expr> {
- super::child_opt(self)
+ pub fn expr(&self) -> Option<Expr> {
+ AstChildren::new(&self.syntax).next()
}
-
- pub fn name_ref(&self) -> Option<&NameRef> {
- super::child_opt(self)
+ pub fn name_ref(&self) -> Option<NameRef> {
+ AstChildren::new(&self.syntax).next()
}
-
- pub fn type_arg_list(&self) -> Option<&TypeArgList> {
- super::child_opt(self)
+ pub fn type_arg_list(&self) -> Option<TypeArgList> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// Module
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Module {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for Module {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for Module {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- MODULE => Some(Module::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ MODULE => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for Module {
- type Owned = TreeArc<Module>;
- fn to_owned(&self) -> TreeArc<Module> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::VisibilityOwner for Module {}
impl ast::NameOwner for Module {}
impl ast::AttrsOwner for Module {}
impl ast::DocCommentsOwner for Module {}
impl Module {
- pub fn item_list(&self) -> Option<&ItemList> {
- super::child_opt(self)
+ pub fn item_list(&self) -> Option<ItemList> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// ModuleItem
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
-pub struct ModuleItem {
- pub(crate) syntax: SyntaxNode,
-}
-unsafe impl TransparentNewType for ModuleItem {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-pub enum ModuleItemKind<'a> {
- StructDef(&'a StructDef),
- EnumDef(&'a EnumDef),
- FnDef(&'a FnDef),
- TraitDef(&'a TraitDef),
- TypeAliasDef(&'a TypeAliasDef),
- ImplBlock(&'a ImplBlock),
- UseItem(&'a UseItem),
- ExternCrateItem(&'a ExternCrateItem),
- ConstDef(&'a ConstDef),
- StaticDef(&'a StaticDef),
- Module(&'a Module),
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub enum ModuleItem {
+ StructDef(StructDef),
+ UnionDef(UnionDef),
+ EnumDef(EnumDef),
+ FnDef(FnDef),
+ TraitDef(TraitDef),
+ TypeAliasDef(TypeAliasDef),
+ ImplBlock(ImplBlock),
+ UseItem(UseItem),
+ ExternCrateItem(ExternCrateItem),
+ ConstDef(ConstDef),
+ StaticDef(StaticDef),
+ Module(Module),
}
-impl<'a> From<&'a StructDef> for &'a ModuleItem {
- fn from(n: &'a StructDef) -> &'a ModuleItem {
- ModuleItem::cast(&n.syntax).unwrap()
+impl From<StructDef> for ModuleItem {
+ fn from(node: StructDef) -> ModuleItem {
+ ModuleItem::StructDef(node)
}
}
-impl<'a> From<&'a EnumDef> for &'a ModuleItem {
- fn from(n: &'a EnumDef) -> &'a ModuleItem {
- ModuleItem::cast(&n.syntax).unwrap()
+impl From<UnionDef> for ModuleItem {
+ fn from(node: UnionDef) -> ModuleItem {
+ ModuleItem::UnionDef(node)
}
}
-impl<'a> From<&'a FnDef> for &'a ModuleItem {
- fn from(n: &'a FnDef) -> &'a ModuleItem {
- ModuleItem::cast(&n.syntax).unwrap()
+impl From<EnumDef> for ModuleItem {
+ fn from(node: EnumDef) -> ModuleItem {
+ ModuleItem::EnumDef(node)
}
}
-impl<'a> From<&'a TraitDef> for &'a ModuleItem {
- fn from(n: &'a TraitDef) -> &'a ModuleItem {
- ModuleItem::cast(&n.syntax).unwrap()
+impl From<FnDef> for ModuleItem {
+ fn from(node: FnDef) -> ModuleItem {
+ ModuleItem::FnDef(node)
}
}
-impl<'a> From<&'a TypeAliasDef> for &'a ModuleItem {
- fn from(n: &'a TypeAliasDef) -> &'a ModuleItem {
- ModuleItem::cast(&n.syntax).unwrap()
+impl From<TraitDef> for ModuleItem {
+ fn from(node: TraitDef) -> ModuleItem {
+ ModuleItem::TraitDef(node)
}
}
-impl<'a> From<&'a ImplBlock> for &'a ModuleItem {
- fn from(n: &'a ImplBlock) -> &'a ModuleItem {
- ModuleItem::cast(&n.syntax).unwrap()
+impl From<TypeAliasDef> for ModuleItem {
+ fn from(node: TypeAliasDef) -> ModuleItem {
+ ModuleItem::TypeAliasDef(node)
}
}
-impl<'a> From<&'a UseItem> for &'a ModuleItem {
- fn from(n: &'a UseItem) -> &'a ModuleItem {
- ModuleItem::cast(&n.syntax).unwrap()
+impl From<ImplBlock> for ModuleItem {
+ fn from(node: ImplBlock) -> ModuleItem {
+ ModuleItem::ImplBlock(node)
}
}
-impl<'a> From<&'a ExternCrateItem> for &'a ModuleItem {
- fn from(n: &'a ExternCrateItem) -> &'a ModuleItem {
- ModuleItem::cast(&n.syntax).unwrap()
+impl From<UseItem> for ModuleItem {
+ fn from(node: UseItem) -> ModuleItem {
+ ModuleItem::UseItem(node)
}
}
-impl<'a> From<&'a ConstDef> for &'a ModuleItem {
- fn from(n: &'a ConstDef) -> &'a ModuleItem {
- ModuleItem::cast(&n.syntax).unwrap()
+impl From<ExternCrateItem> for ModuleItem {
+ fn from(node: ExternCrateItem) -> ModuleItem {
+ ModuleItem::ExternCrateItem(node)
}
}
-impl<'a> From<&'a StaticDef> for &'a ModuleItem {
- fn from(n: &'a StaticDef) -> &'a ModuleItem {
- ModuleItem::cast(&n.syntax).unwrap()
+impl From<ConstDef> for ModuleItem {
+ fn from(node: ConstDef) -> ModuleItem {
+ ModuleItem::ConstDef(node)
}
}
-impl<'a> From<&'a Module> for &'a ModuleItem {
- fn from(n: &'a Module) -> &'a ModuleItem {
- ModuleItem::cast(&n.syntax).unwrap()
+impl From<StaticDef> for ModuleItem {
+ fn from(node: StaticDef) -> ModuleItem {
+ ModuleItem::StaticDef(node)
}
}
-
-
-impl AstNode for ModuleItem {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- | STRUCT_DEF
- | ENUM_DEF
- | FN_DEF
- | TRAIT_DEF
- | TYPE_ALIAS_DEF
- | IMPL_BLOCK
- | USE_ITEM
- | EXTERN_CRATE_ITEM
- | CONST_DEF
- | STATIC_DEF
- | MODULE => Some(ModuleItem::from_repr(syntax.into_repr())),
- _ => None,
- }
- }
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for ModuleItem {
- type Owned = TreeArc<ModuleItem>;
- fn to_owned(&self) -> TreeArc<ModuleItem> { TreeArc::cast(self.syntax.to_owned()) }
-}
-
-impl ModuleItem {
- pub fn kind(&self) -> ModuleItemKind {
- match self.syntax.kind() {
- STRUCT_DEF => ModuleItemKind::StructDef(StructDef::cast(&self.syntax).unwrap()),
- ENUM_DEF => ModuleItemKind::EnumDef(EnumDef::cast(&self.syntax).unwrap()),
- FN_DEF => ModuleItemKind::FnDef(FnDef::cast(&self.syntax).unwrap()),
- TRAIT_DEF => ModuleItemKind::TraitDef(TraitDef::cast(&self.syntax).unwrap()),
- TYPE_ALIAS_DEF => ModuleItemKind::TypeAliasDef(TypeAliasDef::cast(&self.syntax).unwrap()),
- IMPL_BLOCK => ModuleItemKind::ImplBlock(ImplBlock::cast(&self.syntax).unwrap()),
- USE_ITEM => ModuleItemKind::UseItem(UseItem::cast(&self.syntax).unwrap()),
- EXTERN_CRATE_ITEM => ModuleItemKind::ExternCrateItem(ExternCrateItem::cast(&self.syntax).unwrap()),
- CONST_DEF => ModuleItemKind::ConstDef(ConstDef::cast(&self.syntax).unwrap()),
- STATIC_DEF => ModuleItemKind::StaticDef(StaticDef::cast(&self.syntax).unwrap()),
- MODULE => ModuleItemKind::Module(Module::cast(&self.syntax).unwrap()),
- _ => unreachable!(),
- }
+impl From<Module> for ModuleItem {
+ fn from(node: Module) -> ModuleItem {
+ ModuleItem::Module(node)
}
}
-
+impl AstNode for ModuleItem {
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ STRUCT_DEF | UNION_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF
+ | IMPL_BLOCK | USE_ITEM | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE => true,
+ _ => false,
+ }
+ }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ let res = match syntax.kind() {
+ STRUCT_DEF => ModuleItem::StructDef(StructDef { syntax }),
+ UNION_DEF => ModuleItem::UnionDef(UnionDef { syntax }),
+ ENUM_DEF => ModuleItem::EnumDef(EnumDef { syntax }),
+ FN_DEF => ModuleItem::FnDef(FnDef { syntax }),
+ TRAIT_DEF => ModuleItem::TraitDef(TraitDef { syntax }),
+ TYPE_ALIAS_DEF => ModuleItem::TypeAliasDef(TypeAliasDef { syntax }),
+ IMPL_BLOCK => ModuleItem::ImplBlock(ImplBlock { syntax }),
+ USE_ITEM => ModuleItem::UseItem(UseItem { syntax }),
+ EXTERN_CRATE_ITEM => ModuleItem::ExternCrateItem(ExternCrateItem { syntax }),
+ CONST_DEF => ModuleItem::ConstDef(ConstDef { syntax }),
+ STATIC_DEF => ModuleItem::StaticDef(StaticDef { syntax }),
+ MODULE => ModuleItem::Module(Module { syntax }),
+ _ => return None,
+ };
+ Some(res)
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ match self {
+ ModuleItem::StructDef(it) => &it.syntax,
+ ModuleItem::UnionDef(it) => &it.syntax,
+ ModuleItem::EnumDef(it) => &it.syntax,
+ ModuleItem::FnDef(it) => &it.syntax,
+ ModuleItem::TraitDef(it) => &it.syntax,
+ ModuleItem::TypeAliasDef(it) => &it.syntax,
+ ModuleItem::ImplBlock(it) => &it.syntax,
+ ModuleItem::UseItem(it) => &it.syntax,
+ ModuleItem::ExternCrateItem(it) => &it.syntax,
+ ModuleItem::ConstDef(it) => &it.syntax,
+ ModuleItem::StaticDef(it) => &it.syntax,
+ ModuleItem::Module(it) => &it.syntax,
+ }
+ }
+}
+impl ast::AttrsOwner for ModuleItem {}
impl ModuleItem {}
-
-// Name
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Name {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for Name {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for Name {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- NAME => Some(Name::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ NAME => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for Name {
- type Owned = TreeArc<Name>;
- fn to_owned(&self) -> TreeArc<Name> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl Name {}
-
-// NameRef
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct NameRef {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for NameRef {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for NameRef {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- NAME_REF => Some(NameRef::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ NAME_REF => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for NameRef {
- type Owned = TreeArc<NameRef>;
- fn to_owned(&self) -> TreeArc<NameRef> { TreeArc::cast(self.syntax.to_owned()) }
-}
-
-
-impl NameRef {}
-
-// NamedField
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
-pub struct NamedField {
- pub(crate) syntax: SyntaxNode,
-}
-unsafe impl TransparentNewType for NamedField {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
-impl AstNode for NamedField {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- NAMED_FIELD => Some(NamedField::from_repr(syntax.into_repr())),
- _ => None,
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for NamedField {
- type Owned = TreeArc<NamedField>;
- fn to_owned(&self) -> TreeArc<NamedField> { TreeArc::cast(self.syntax.to_owned()) }
-}
-
-
-impl NamedField {
- pub fn name_ref(&self) -> Option<&NameRef> {
- super::child_opt(self)
- }
-
- pub fn expr(&self) -> Option<&Expr> {
- super::child_opt(self)
- }
-}
-
-// NamedFieldDef
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
-pub struct NamedFieldDef {
- pub(crate) syntax: SyntaxNode,
-}
-unsafe impl TransparentNewType for NamedFieldDef {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
-impl AstNode for NamedFieldDef {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- NAMED_FIELD_DEF => Some(NamedFieldDef::from_repr(syntax.into_repr())),
- _ => None,
- }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for NamedFieldDef {
- type Owned = TreeArc<NamedFieldDef>;
- fn to_owned(&self) -> TreeArc<NamedFieldDef> { TreeArc::cast(self.syntax.to_owned()) }
}
-
-
-impl ast::VisibilityOwner for NamedFieldDef {}
-impl ast::NameOwner for NamedFieldDef {}
-impl ast::AttrsOwner for NamedFieldDef {}
-impl ast::DocCommentsOwner for NamedFieldDef {}
-impl ast::TypeAscriptionOwner for NamedFieldDef {}
-impl NamedFieldDef {}
-
-// NamedFieldDefList
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
-pub struct NamedFieldDefList {
+impl NameRef {}
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct NeverType {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for NamedFieldDefList {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
-impl AstNode for NamedFieldDefList {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- NAMED_FIELD_DEF_LIST => Some(NamedFieldDefList::from_repr(syntax.into_repr())),
- _ => None,
+impl AstNode for NeverType {
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ NEVER_TYPE => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for NamedFieldDefList {
- type Owned = TreeArc<NamedFieldDefList>;
- fn to_owned(&self) -> TreeArc<NamedFieldDefList> { TreeArc::cast(self.syntax.to_owned()) }
-}
-
-
-impl NamedFieldDefList {
- pub fn fields(&self) -> impl Iterator<Item = &NamedFieldDef> {
- super::children(self)
- }
-}
-
-// NamedFieldList
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
-pub struct NamedFieldList {
- pub(crate) syntax: SyntaxNode,
-}
-unsafe impl TransparentNewType for NamedFieldList {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
-impl AstNode for NamedFieldList {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- NAMED_FIELD_LIST => Some(NamedFieldList::from_repr(syntax.into_repr())),
- _ => None,
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for NamedFieldList {
- type Owned = TreeArc<NamedFieldList>;
- fn to_owned(&self) -> TreeArc<NamedFieldList> { TreeArc::cast(self.syntax.to_owned()) }
-}
-
-
-impl NamedFieldList {
- pub fn fields(&self) -> impl Iterator<Item = &NamedField> {
- super::children(self)
- }
-}
-
-// NeverType
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
-pub struct NeverType {
- pub(crate) syntax: SyntaxNode,
-}
-unsafe impl TransparentNewType for NeverType {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
-impl AstNode for NeverType {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- NEVER_TYPE => Some(NeverType::from_repr(syntax.into_repr())),
- _ => None,
- }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for NeverType {
- type Owned = TreeArc<NeverType>;
- fn to_owned(&self) -> TreeArc<NeverType> { TreeArc::cast(self.syntax.to_owned()) }
}
-
-
impl NeverType {}
-
-// NominalDef
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
-pub struct NominalDef {
- pub(crate) syntax: SyntaxNode,
-}
-unsafe impl TransparentNewType for NominalDef {
- type Repr = rowan::SyntaxNode<RaTypes>;
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub enum NominalDef {
+ StructDef(StructDef),
+ EnumDef(EnumDef),
+ UnionDef(UnionDef),
}
-
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-pub enum NominalDefKind<'a> {
- StructDef(&'a StructDef),
- EnumDef(&'a EnumDef),
+impl From<StructDef> for NominalDef {
+ fn from(node: StructDef) -> NominalDef {
+ NominalDef::StructDef(node)
+ }
}
-impl<'a> From<&'a StructDef> for &'a NominalDef {
- fn from(n: &'a StructDef) -> &'a NominalDef {
- NominalDef::cast(&n.syntax).unwrap()
+impl From<EnumDef> for NominalDef {
+ fn from(node: EnumDef) -> NominalDef {
+ NominalDef::EnumDef(node)
}
}
-impl<'a> From<&'a EnumDef> for &'a NominalDef {
- fn from(n: &'a EnumDef) -> &'a NominalDef {
- NominalDef::cast(&n.syntax).unwrap()
+impl From<UnionDef> for NominalDef {
+ fn from(node: UnionDef) -> NominalDef {
+ NominalDef::UnionDef(node)
}
}
-
-
impl AstNode for NominalDef {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- | STRUCT_DEF
- | ENUM_DEF => Some(NominalDef::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ STRUCT_DEF | ENUM_DEF | UNION_DEF => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for NominalDef {
- type Owned = TreeArc<NominalDef>;
- fn to_owned(&self) -> TreeArc<NominalDef> { TreeArc::cast(self.syntax.to_owned()) }
-}
-
-impl NominalDef {
- pub fn kind(&self) -> NominalDefKind {
- match self.syntax.kind() {
- STRUCT_DEF => NominalDefKind::StructDef(StructDef::cast(&self.syntax).unwrap()),
- ENUM_DEF => NominalDefKind::EnumDef(EnumDef::cast(&self.syntax).unwrap()),
- _ => unreachable!(),
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ let res = match syntax.kind() {
+ STRUCT_DEF => NominalDef::StructDef(StructDef { syntax }),
+ ENUM_DEF => NominalDef::EnumDef(EnumDef { syntax }),
+ UNION_DEF => NominalDef::UnionDef(UnionDef { syntax }),
+ _ => return None,
+ };
+ Some(res)
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ match self {
+ NominalDef::StructDef(it) => &it.syntax,
+ NominalDef::EnumDef(it) => &it.syntax,
+ NominalDef::UnionDef(it) => &it.syntax,
}
}
}
-
impl ast::NameOwner for NominalDef {}
impl ast::TypeParamsOwner for NominalDef {}
impl ast::AttrsOwner for NominalDef {}
impl NominalDef {}
-
-// Param
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Param {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for Param {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for Param {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- PARAM => Some(Param::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ PARAM => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for Param {
- type Owned = TreeArc<Param>;
- fn to_owned(&self) -> TreeArc<Param> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::TypeAscriptionOwner for Param {}
+impl ast::AttrsOwner for Param {}
impl Param {
- pub fn pat(&self) -> Option<&Pat> {
- super::child_opt(self)
+ pub fn pat(&self) -> Option<Pat> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// ParamList
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ParamList {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for ParamList {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for ParamList {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- PARAM_LIST => Some(ParamList::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ PARAM_LIST => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for ParamList {
- type Owned = TreeArc<ParamList>;
- fn to_owned(&self) -> TreeArc<ParamList> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ParamList {
- pub fn params(&self) -> impl Iterator<Item = &Param> {
- super::children(self)
+ pub fn params(&self) -> AstChildren<Param> {
+ AstChildren::new(&self.syntax)
}
-
- pub fn self_param(&self) -> Option<&SelfParam> {
- super::child_opt(self)
+ pub fn self_param(&self) -> Option<SelfParam> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// ParenExpr
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ParenExpr {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for ParenExpr {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for ParenExpr {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- PAREN_EXPR => Some(ParenExpr::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ PAREN_EXPR => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for ParenExpr {
- type Owned = TreeArc<ParenExpr>;
- fn to_owned(&self) -> TreeArc<ParenExpr> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ParenExpr {
- pub fn expr(&self) -> Option<&Expr> {
- super::child_opt(self)
+ pub fn expr(&self) -> Option<Expr> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// ParenType
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ParenType {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for ParenType {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for ParenType {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- PAREN_TYPE => Some(ParenType::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ PAREN_TYPE => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for ParenType {
- type Owned = TreeArc<ParenType>;
- fn to_owned(&self) -> TreeArc<ParenType> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ParenType {
- pub fn type_ref(&self) -> Option<&TypeRef> {
- super::child_opt(self)
+ pub fn type_ref(&self) -> Option<TypeRef> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// Pat
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
-pub struct Pat {
- pub(crate) syntax: SyntaxNode,
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub enum Pat {
+ RefPat(RefPat),
+ BoxPat(BoxPat),
+ BindPat(BindPat),
+ PlaceholderPat(PlaceholderPat),
+ DotDotPat(DotDotPat),
+ PathPat(PathPat),
+ RecordPat(RecordPat),
+ TupleStructPat(TupleStructPat),
+ TuplePat(TuplePat),
+ SlicePat(SlicePat),
+ RangePat(RangePat),
+ LiteralPat(LiteralPat),
}
-unsafe impl TransparentNewType for Pat {
- type Repr = rowan::SyntaxNode<RaTypes>;
+impl From<RefPat> for Pat {
+ fn from(node: RefPat) -> Pat {
+ Pat::RefPat(node)
+ }
}
-
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-pub enum PatKind<'a> {
- RefPat(&'a RefPat),
- BindPat(&'a BindPat),
- PlaceholderPat(&'a PlaceholderPat),
- PathPat(&'a PathPat),
- StructPat(&'a StructPat),
- TupleStructPat(&'a TupleStructPat),
- TuplePat(&'a TuplePat),
- SlicePat(&'a SlicePat),
- RangePat(&'a RangePat),
- LiteralPat(&'a LiteralPat),
+impl From<BoxPat> for Pat {
+ fn from(node: BoxPat) -> Pat {
+ Pat::BoxPat(node)
+ }
}
-impl<'a> From<&'a RefPat> for &'a Pat {
- fn from(n: &'a RefPat) -> &'a Pat {
- Pat::cast(&n.syntax).unwrap()
+impl From<BindPat> for Pat {
+ fn from(node: BindPat) -> Pat {
+ Pat::BindPat(node)
}
}
-impl<'a> From<&'a BindPat> for &'a Pat {
- fn from(n: &'a BindPat) -> &'a Pat {
- Pat::cast(&n.syntax).unwrap()
+impl From<PlaceholderPat> for Pat {
+ fn from(node: PlaceholderPat) -> Pat {
+ Pat::PlaceholderPat(node)
}
}
-impl<'a> From<&'a PlaceholderPat> for &'a Pat {
- fn from(n: &'a PlaceholderPat) -> &'a Pat {
- Pat::cast(&n.syntax).unwrap()
+impl From<DotDotPat> for Pat {
+ fn from(node: DotDotPat) -> Pat {
+ Pat::DotDotPat(node)
}
}
-impl<'a> From<&'a PathPat> for &'a Pat {
- fn from(n: &'a PathPat) -> &'a Pat {
- Pat::cast(&n.syntax).unwrap()
+impl From<PathPat> for Pat {
+ fn from(node: PathPat) -> Pat {
+ Pat::PathPat(node)
}
}
-impl<'a> From<&'a StructPat> for &'a Pat {
- fn from(n: &'a StructPat) -> &'a Pat {
- Pat::cast(&n.syntax).unwrap()
+impl From<RecordPat> for Pat {
+ fn from(node: RecordPat) -> Pat {
+ Pat::RecordPat(node)
}
}
-impl<'a> From<&'a TupleStructPat> for &'a Pat {
- fn from(n: &'a TupleStructPat) -> &'a Pat {
- Pat::cast(&n.syntax).unwrap()
+impl From<TupleStructPat> for Pat {
+ fn from(node: TupleStructPat) -> Pat {
+ Pat::TupleStructPat(node)
}
}
-impl<'a> From<&'a TuplePat> for &'a Pat {
- fn from(n: &'a TuplePat) -> &'a Pat {
- Pat::cast(&n.syntax).unwrap()
+impl From<TuplePat> for Pat {
+ fn from(node: TuplePat) -> Pat {
+ Pat::TuplePat(node)
}
}
-impl<'a> From<&'a SlicePat> for &'a Pat {
- fn from(n: &'a SlicePat) -> &'a Pat {
- Pat::cast(&n.syntax).unwrap()
+impl From<SlicePat> for Pat {
+ fn from(node: SlicePat) -> Pat {
+ Pat::SlicePat(node)
}
}
-impl<'a> From<&'a RangePat> for &'a Pat {
- fn from(n: &'a RangePat) -> &'a Pat {
- Pat::cast(&n.syntax).unwrap()
+impl From<RangePat> for Pat {
+ fn from(node: RangePat) -> Pat {
+ Pat::RangePat(node)
}
}
-impl<'a> From<&'a LiteralPat> for &'a Pat {
- fn from(n: &'a LiteralPat) -> &'a Pat {
- Pat::cast(&n.syntax).unwrap()
+impl From<LiteralPat> for Pat {
+ fn from(node: LiteralPat) -> Pat {
+ Pat::LiteralPat(node)
}
}
-
-
impl AstNode for Pat {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- | REF_PAT
- | BIND_PAT
- | PLACEHOLDER_PAT
- | PATH_PAT
- | STRUCT_PAT
- | TUPLE_STRUCT_PAT
- | TUPLE_PAT
- | SLICE_PAT
- | RANGE_PAT
- | LITERAL_PAT => Some(Pat::from_repr(syntax.into_repr())),
- _ => None,
- }
- }
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for Pat {
- type Owned = TreeArc<Pat>;
- fn to_owned(&self) -> TreeArc<Pat> { TreeArc::cast(self.syntax.to_owned()) }
-}
-
-impl Pat {
- pub fn kind(&self) -> PatKind {
- match self.syntax.kind() {
- REF_PAT => PatKind::RefPat(RefPat::cast(&self.syntax).unwrap()),
- BIND_PAT => PatKind::BindPat(BindPat::cast(&self.syntax).unwrap()),
- PLACEHOLDER_PAT => PatKind::PlaceholderPat(PlaceholderPat::cast(&self.syntax).unwrap()),
- PATH_PAT => PatKind::PathPat(PathPat::cast(&self.syntax).unwrap()),
- STRUCT_PAT => PatKind::StructPat(StructPat::cast(&self.syntax).unwrap()),
- TUPLE_STRUCT_PAT => PatKind::TupleStructPat(TupleStructPat::cast(&self.syntax).unwrap()),
- TUPLE_PAT => PatKind::TuplePat(TuplePat::cast(&self.syntax).unwrap()),
- SLICE_PAT => PatKind::SlicePat(SlicePat::cast(&self.syntax).unwrap()),
- RANGE_PAT => PatKind::RangePat(RangePat::cast(&self.syntax).unwrap()),
- LITERAL_PAT => PatKind::LiteralPat(LiteralPat::cast(&self.syntax).unwrap()),
- _ => unreachable!(),
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ REF_PAT | BOX_PAT | BIND_PAT | PLACEHOLDER_PAT | DOT_DOT_PAT | PATH_PAT
+ | RECORD_PAT | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => {
+ true
+ }
+ _ => false,
+ }
+ }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ let res = match syntax.kind() {
+ REF_PAT => Pat::RefPat(RefPat { syntax }),
+ BOX_PAT => Pat::BoxPat(BoxPat { syntax }),
+ BIND_PAT => Pat::BindPat(BindPat { syntax }),
+ PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }),
+ DOT_DOT_PAT => Pat::DotDotPat(DotDotPat { syntax }),
+ PATH_PAT => Pat::PathPat(PathPat { syntax }),
+ RECORD_PAT => Pat::RecordPat(RecordPat { syntax }),
+ TUPLE_STRUCT_PAT => Pat::TupleStructPat(TupleStructPat { syntax }),
+ TUPLE_PAT => Pat::TuplePat(TuplePat { syntax }),
+ SLICE_PAT => Pat::SlicePat(SlicePat { syntax }),
+ RANGE_PAT => Pat::RangePat(RangePat { syntax }),
+ LITERAL_PAT => Pat::LiteralPat(LiteralPat { syntax }),
+ _ => return None,
+ };
+ Some(res)
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ match self {
+ Pat::RefPat(it) => &it.syntax,
+ Pat::BoxPat(it) => &it.syntax,
+ Pat::BindPat(it) => &it.syntax,
+ Pat::PlaceholderPat(it) => &it.syntax,
+ Pat::DotDotPat(it) => &it.syntax,
+ Pat::PathPat(it) => &it.syntax,
+ Pat::RecordPat(it) => &it.syntax,
+ Pat::TupleStructPat(it) => &it.syntax,
+ Pat::TuplePat(it) => &it.syntax,
+ Pat::SlicePat(it) => &it.syntax,
+ Pat::RangePat(it) => &it.syntax,
+ Pat::LiteralPat(it) => &it.syntax,
}
}
}
-
impl Pat {}
-
-// Path
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Path {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for Path {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for Path {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- PATH => Some(Path::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ PATH => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for Path {
- type Owned = TreeArc<Path>;
- fn to_owned(&self) -> TreeArc<Path> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl Path {
- pub fn segment(&self) -> Option<&PathSegment> {
- super::child_opt(self)
+ pub fn segment(&self) -> Option<PathSegment> {
+ AstChildren::new(&self.syntax).next()
}
-
- pub fn qualifier(&self) -> Option<&Path> {
- super::child_opt(self)
+ pub fn qualifier(&self) -> Option<Path> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// PathExpr
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct PathExpr {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for PathExpr {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for PathExpr {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- PATH_EXPR => Some(PathExpr::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ PATH_EXPR => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for PathExpr {
- type Owned = TreeArc<PathExpr>;
- fn to_owned(&self) -> TreeArc<PathExpr> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl PathExpr {
- pub fn path(&self) -> Option<&Path> {
- super::child_opt(self)
+ pub fn path(&self) -> Option<Path> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// PathPat
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct PathPat {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for PathPat {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for PathPat {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- PATH_PAT => Some(PathPat::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ PATH_PAT => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for PathPat {
- type Owned = TreeArc<PathPat>;
- fn to_owned(&self) -> TreeArc<PathPat> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl PathPat {
- pub fn path(&self) -> Option<&Path> {
- super::child_opt(self)
+ pub fn path(&self) -> Option<Path> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// PathSegment
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct PathSegment {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for PathSegment {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for PathSegment {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- PATH_SEGMENT => Some(PathSegment::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ PATH_SEGMENT => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for PathSegment {
- type Owned = TreeArc<PathSegment>;
- fn to_owned(&self) -> TreeArc<PathSegment> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl PathSegment {
- pub fn name_ref(&self) -> Option<&NameRef> {
- super::child_opt(self)
+ pub fn name_ref(&self) -> Option<NameRef> {
+ AstChildren::new(&self.syntax).next()
}
-
- pub fn type_arg_list(&self) -> Option<&TypeArgList> {
- super::child_opt(self)
+ pub fn type_arg_list(&self) -> Option<TypeArgList> {
+ AstChildren::new(&self.syntax).next()
+ }
+ pub fn param_list(&self) -> Option<ParamList> {
+ AstChildren::new(&self.syntax).next()
+ }
+ pub fn ret_type(&self) -> Option<RetType> {
+ AstChildren::new(&self.syntax).next()
+ }
+ pub fn path_type(&self) -> Option<PathType> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// PathType
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct PathType {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for PathType {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for PathType {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- PATH_TYPE => Some(PathType::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ PATH_TYPE => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for PathType {
- type Owned = TreeArc<PathType>;
- fn to_owned(&self) -> TreeArc<PathType> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl PathType {
- pub fn path(&self) -> Option<&Path> {
- super::child_opt(self)
+ pub fn path(&self) -> Option<Path> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// PlaceholderPat
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct PlaceholderPat {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for PlaceholderPat {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for PlaceholderPat {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- PLACEHOLDER_PAT => Some(PlaceholderPat::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ PLACEHOLDER_PAT => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for PlaceholderPat {
- type Owned = TreeArc<PlaceholderPat>;
- fn to_owned(&self) -> TreeArc<PlaceholderPat> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl PlaceholderPat {}
-
-// PlaceholderType
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct PlaceholderType {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for PlaceholderType {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for PlaceholderType {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- PLACEHOLDER_TYPE => Some(PlaceholderType::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ PLACEHOLDER_TYPE => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for PlaceholderType {
- type Owned = TreeArc<PlaceholderType>;
- fn to_owned(&self) -> TreeArc<PlaceholderType> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl PlaceholderType {}
-
-// PointerType
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct PointerType {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for PointerType {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for PointerType {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- POINTER_TYPE => Some(PointerType::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ POINTER_TYPE => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for PointerType {
- type Owned = TreeArc<PointerType>;
- fn to_owned(&self) -> TreeArc<PointerType> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl PointerType {
- pub fn type_ref(&self) -> Option<&TypeRef> {
- super::child_opt(self)
+ pub fn type_ref(&self) -> Option<TypeRef> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// PosFieldDef
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
-pub struct PosFieldDef {
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct PrefixExpr {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for PosFieldDef {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
-impl AstNode for PosFieldDef {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- POS_FIELD_DEF => Some(PosFieldDef::from_repr(syntax.into_repr())),
- _ => None,
+impl AstNode for PrefixExpr {
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ PREFIX_EXPR => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for PosFieldDef {
- type Owned = TreeArc<PosFieldDef>;
- fn to_owned(&self) -> TreeArc<PosFieldDef> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
-impl ast::VisibilityOwner for PosFieldDef {}
-impl ast::AttrsOwner for PosFieldDef {}
-impl PosFieldDef {
- pub fn type_ref(&self) -> Option<&TypeRef> {
- super::child_opt(self)
+impl PrefixExpr {
+ pub fn expr(&self) -> Option<Expr> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// PosFieldDefList
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
-pub struct PosFieldDefList {
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct RangeExpr {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for PosFieldDefList {
- type Repr = rowan::SyntaxNode<RaTypes>;
+impl AstNode for RangeExpr {
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ RANGE_EXPR => true,
+ _ => false,
+ }
+ }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-impl AstNode for PosFieldDefList {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- POS_FIELD_DEF_LIST => Some(PosFieldDefList::from_repr(syntax.into_repr())),
- _ => None,
+impl RangeExpr {}
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct RangePat {
+ pub(crate) syntax: SyntaxNode,
+}
+impl AstNode for RangePat {
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ RANGE_PAT => true,
+ _ => false,
+ }
+ }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-impl ToOwned for PosFieldDefList {
- type Owned = TreeArc<PosFieldDefList>;
- fn to_owned(&self) -> TreeArc<PosFieldDefList> { TreeArc::cast(self.syntax.to_owned()) }
+impl RangePat {}
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct RecordField {
+ pub(crate) syntax: SyntaxNode,
}
-
-
-impl PosFieldDefList {
- pub fn fields(&self) -> impl Iterator<Item = &PosFieldDef> {
- super::children(self)
+impl AstNode for RecordField {
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ RECORD_FIELD => true,
+ _ => false,
+ }
+ }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
}
}
-
-// PrefixExpr
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
-pub struct PrefixExpr {
+impl RecordField {
+ pub fn name_ref(&self) -> Option<NameRef> {
+ AstChildren::new(&self.syntax).next()
+ }
+ pub fn expr(&self) -> Option<Expr> {
+ AstChildren::new(&self.syntax).next()
+ }
+}
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct RecordFieldDef {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for PrefixExpr {
- type Repr = rowan::SyntaxNode<RaTypes>;
+impl AstNode for RecordFieldDef {
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ RECORD_FIELD_DEF => true,
+ _ => false,
+ }
+ }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
+}
+impl ast::VisibilityOwner for RecordFieldDef {}
+impl ast::NameOwner for RecordFieldDef {}
+impl ast::AttrsOwner for RecordFieldDef {}
+impl ast::DocCommentsOwner for RecordFieldDef {}
+impl ast::TypeAscriptionOwner for RecordFieldDef {}
+impl RecordFieldDef {}
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct RecordFieldDefList {
+ pub(crate) syntax: SyntaxNode,
}
-
-impl AstNode for PrefixExpr {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- PREFIX_EXPR => Some(PrefixExpr::from_repr(syntax.into_repr())),
- _ => None,
+impl AstNode for RecordFieldDefList {
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ RECORD_FIELD_DEF_LIST => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-impl ToOwned for PrefixExpr {
- type Owned = TreeArc<PrefixExpr>;
- fn to_owned(&self) -> TreeArc<PrefixExpr> { TreeArc::cast(self.syntax.to_owned()) }
+impl RecordFieldDefList {
+ pub fn fields(&self) -> AstChildren<RecordFieldDef> {
+ AstChildren::new(&self.syntax)
+ }
}
-
-
-impl PrefixExpr {
- pub fn expr(&self) -> Option<&Expr> {
- super::child_opt(self)
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct RecordFieldList {
+ pub(crate) syntax: SyntaxNode,
+}
+impl AstNode for RecordFieldList {
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ RECORD_FIELD_LIST => true,
+ _ => false,
+ }
+ }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
}
}
-
-// RangeExpr
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
-pub struct RangeExpr {
+impl RecordFieldList {
+ pub fn fields(&self) -> AstChildren<RecordField> {
+ AstChildren::new(&self.syntax)
+ }
+ pub fn spread(&self) -> Option<Expr> {
+ AstChildren::new(&self.syntax).next()
+ }
+}
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct RecordFieldPat {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for RangeExpr {
- type Repr = rowan::SyntaxNode<RaTypes>;
+impl AstNode for RecordFieldPat {
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ RECORD_FIELD_PAT => true,
+ _ => false,
+ }
+ }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
+}
+impl ast::NameOwner for RecordFieldPat {}
+impl RecordFieldPat {
+ pub fn pat(&self) -> Option<Pat> {
+ AstChildren::new(&self.syntax).next()
+ }
}
-
-impl AstNode for RangeExpr {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- RANGE_EXPR => Some(RangeExpr::from_repr(syntax.into_repr())),
- _ => None,
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct RecordFieldPatList {
+ pub(crate) syntax: SyntaxNode,
+}
+impl AstNode for RecordFieldPatList {
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ RECORD_FIELD_PAT_LIST => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-impl ToOwned for RangeExpr {
- type Owned = TreeArc<RangeExpr>;
- fn to_owned(&self) -> TreeArc<RangeExpr> { TreeArc::cast(self.syntax.to_owned()) }
+impl RecordFieldPatList {
+ pub fn record_field_pats(&self) -> AstChildren<RecordFieldPat> {
+ AstChildren::new(&self.syntax)
+ }
+ pub fn bind_pats(&self) -> AstChildren<BindPat> {
+ AstChildren::new(&self.syntax)
+ }
}
-
-
-impl RangeExpr {}
-
-// RangePat
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
-pub struct RangePat {
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct RecordLit {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for RangePat {
- type Repr = rowan::SyntaxNode<RaTypes>;
+impl AstNode for RecordLit {
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ RECORD_LIT => true,
+ _ => false,
+ }
+ }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-impl AstNode for RangePat {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- RANGE_PAT => Some(RangePat::from_repr(syntax.into_repr())),
- _ => None,
+impl RecordLit {
+ pub fn path(&self) -> Option<Path> {
+ AstChildren::new(&self.syntax).next()
+ }
+ pub fn record_field_list(&self) -> Option<RecordFieldList> {
+ AstChildren::new(&self.syntax).next()
+ }
+}
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct RecordPat {
+ pub(crate) syntax: SyntaxNode,
+}
+impl AstNode for RecordPat {
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ RECORD_PAT => true,
+ _ => false,
+ }
+ }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-impl ToOwned for RangePat {
- type Owned = TreeArc<RangePat>;
- fn to_owned(&self) -> TreeArc<RangePat> { TreeArc::cast(self.syntax.to_owned()) }
+impl RecordPat {
+ pub fn record_field_pat_list(&self) -> Option<RecordFieldPatList> {
+ AstChildren::new(&self.syntax).next()
+ }
+ pub fn path(&self) -> Option<Path> {
+ AstChildren::new(&self.syntax).next()
+ }
}
-
-
-impl RangePat {}
-
-// RefExpr
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct RefExpr {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for RefExpr {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for RefExpr {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- REF_EXPR => Some(RefExpr::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ REF_EXPR => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for RefExpr {
- type Owned = TreeArc<RefExpr>;
- fn to_owned(&self) -> TreeArc<RefExpr> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl RefExpr {
- pub fn expr(&self) -> Option<&Expr> {
- super::child_opt(self)
+ pub fn expr(&self) -> Option<Expr> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// RefPat
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct RefPat {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for RefPat {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for RefPat {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- REF_PAT => Some(RefPat::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ REF_PAT => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for RefPat {
- type Owned = TreeArc<RefPat>;
- fn to_owned(&self) -> TreeArc<RefPat> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl RefPat {
- pub fn pat(&self) -> Option<&Pat> {
- super::child_opt(self)
+ pub fn pat(&self) -> Option<Pat> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// ReferenceType
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ReferenceType {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for ReferenceType {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for ReferenceType {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- REFERENCE_TYPE => Some(ReferenceType::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ REFERENCE_TYPE => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for ReferenceType {
- type Owned = TreeArc<ReferenceType>;
- fn to_owned(&self) -> TreeArc<ReferenceType> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ReferenceType {
- pub fn type_ref(&self) -> Option<&TypeRef> {
- super::child_opt(self)
+ pub fn type_ref(&self) -> Option<TypeRef> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// RetType
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct RetType {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for RetType {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for RetType {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- RET_TYPE => Some(RetType::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ RET_TYPE => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for RetType {
- type Owned = TreeArc<RetType>;
- fn to_owned(&self) -> TreeArc<RetType> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl RetType {
- pub fn type_ref(&self) -> Option<&TypeRef> {
- super::child_opt(self)
+ pub fn type_ref(&self) -> Option<TypeRef> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// ReturnExpr
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ReturnExpr {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for ReturnExpr {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for ReturnExpr {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- RETURN_EXPR => Some(ReturnExpr::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ RETURN_EXPR => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for ReturnExpr {
- type Owned = TreeArc<ReturnExpr>;
- fn to_owned(&self) -> TreeArc<ReturnExpr> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ReturnExpr {
- pub fn expr(&self) -> Option<&Expr> {
- super::child_opt(self)
+ pub fn expr(&self) -> Option<Expr> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// SelfParam
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct SelfParam {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for SelfParam {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for SelfParam {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- SELF_PARAM => Some(SelfParam::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ SELF_PARAM => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for SelfParam {
- type Owned = TreeArc<SelfParam>;
- fn to_owned(&self) -> TreeArc<SelfParam> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::TypeAscriptionOwner for SelfParam {}
+impl ast::AttrsOwner for SelfParam {}
impl SelfParam {}
-
-// SlicePat
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct SlicePat {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for SlicePat {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for SlicePat {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- SLICE_PAT => Some(SlicePat::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ SLICE_PAT => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for SlicePat {
- type Owned = TreeArc<SlicePat>;
- fn to_owned(&self) -> TreeArc<SlicePat> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl SlicePat {}
-
-// SliceType
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct SliceType {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for SliceType {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for SliceType {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- SLICE_TYPE => Some(SliceType::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ SLICE_TYPE => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for SliceType {
- type Owned = TreeArc<SliceType>;
- fn to_owned(&self) -> TreeArc<SliceType> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl SliceType {
- pub fn type_ref(&self) -> Option<&TypeRef> {
- super::child_opt(self)
+ pub fn type_ref(&self) -> Option<TypeRef> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// SourceFile
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct SourceFile {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for SourceFile {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for SourceFile {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- SOURCE_FILE => Some(SourceFile::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ SOURCE_FILE => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for SourceFile {
- type Owned = TreeArc<SourceFile>;
- fn to_owned(&self) -> TreeArc<SourceFile> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::ModuleItemOwner for SourceFile {}
impl ast::FnDefOwner for SourceFile {}
impl SourceFile {
- pub fn modules(&self) -> impl Iterator<Item = &Module> {
- super::children(self)
+ pub fn modules(&self) -> AstChildren<Module> {
+ AstChildren::new(&self.syntax)
}
}
-
-// StaticDef
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct StaticDef {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for StaticDef {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for StaticDef {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- STATIC_DEF => Some(StaticDef::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ STATIC_DEF => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for StaticDef {
- type Owned = TreeArc<StaticDef>;
- fn to_owned(&self) -> TreeArc<StaticDef> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::VisibilityOwner for StaticDef {}
impl ast::NameOwner for StaticDef {}
impl ast::TypeParamsOwner for StaticDef {}
impl ast::AttrsOwner for StaticDef {}
impl ast::DocCommentsOwner for StaticDef {}
impl ast::TypeAscriptionOwner for StaticDef {}
-impl StaticDef {}
-
-// Stmt
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
-pub struct Stmt {
- pub(crate) syntax: SyntaxNode,
-}
-unsafe impl TransparentNewType for Stmt {
- type Repr = rowan::SyntaxNode<RaTypes>;
+impl StaticDef {
+ pub fn body(&self) -> Option<Expr> {
+ AstChildren::new(&self.syntax).next()
+ }
}
-
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-pub enum StmtKind<'a> {
- ExprStmt(&'a ExprStmt),
- LetStmt(&'a LetStmt),
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub enum Stmt {
+ ExprStmt(ExprStmt),
+ LetStmt(LetStmt),
}
-impl<'a> From<&'a ExprStmt> for &'a Stmt {
- fn from(n: &'a ExprStmt) -> &'a Stmt {
- Stmt::cast(&n.syntax).unwrap()
+impl From<ExprStmt> for Stmt {
+ fn from(node: ExprStmt) -> Stmt {
+ Stmt::ExprStmt(node)
}
}
-impl<'a> From<&'a LetStmt> for &'a Stmt {
- fn from(n: &'a LetStmt) -> &'a Stmt {
- Stmt::cast(&n.syntax).unwrap()
+impl From<LetStmt> for Stmt {
+ fn from(node: LetStmt) -> Stmt {
+ Stmt::LetStmt(node)
}
}
-
-
impl AstNode for Stmt {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- | EXPR_STMT
- | LET_STMT => Some(Stmt::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ EXPR_STMT | LET_STMT => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for Stmt {
- type Owned = TreeArc<Stmt>;
- fn to_owned(&self) -> TreeArc<Stmt> { TreeArc::cast(self.syntax.to_owned()) }
-}
-
-impl Stmt {
- pub fn kind(&self) -> StmtKind {
- match self.syntax.kind() {
- EXPR_STMT => StmtKind::ExprStmt(ExprStmt::cast(&self.syntax).unwrap()),
- LET_STMT => StmtKind::LetStmt(LetStmt::cast(&self.syntax).unwrap()),
- _ => unreachable!(),
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ let res = match syntax.kind() {
+ EXPR_STMT => Stmt::ExprStmt(ExprStmt { syntax }),
+ LET_STMT => Stmt::LetStmt(LetStmt { syntax }),
+ _ => return None,
+ };
+ Some(res)
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ match self {
+ Stmt::ExprStmt(it) => &it.syntax,
+ Stmt::LetStmt(it) => &it.syntax,
}
}
}
-
impl Stmt {}
-
-// StructDef
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct StructDef {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for StructDef {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for StructDef {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- STRUCT_DEF => Some(StructDef::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ STRUCT_DEF => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for StructDef {
- type Owned = TreeArc<StructDef>;
- fn to_owned(&self) -> TreeArc<StructDef> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::VisibilityOwner for StructDef {}
impl ast::NameOwner for StructDef {}
impl ast::TypeParamsOwner for StructDef {}
impl ast::AttrsOwner for StructDef {}
impl ast::DocCommentsOwner for StructDef {}
impl StructDef {}
-
-// StructLit
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
-pub struct StructLit {
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct TokenTree {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for StructLit {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
-impl AstNode for StructLit {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- STRUCT_LIT => Some(StructLit::from_repr(syntax.into_repr())),
- _ => None,
+impl AstNode for TokenTree {
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ TOKEN_TREE => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for StructLit {
- type Owned = TreeArc<StructLit>;
- fn to_owned(&self) -> TreeArc<StructLit> { TreeArc::cast(self.syntax.to_owned()) }
-}
-
-
-impl StructLit {
- pub fn path(&self) -> Option<&Path> {
- super::child_opt(self)
- }
-
- pub fn named_field_list(&self) -> Option<&NamedFieldList> {
- super::child_opt(self)
- }
-
- pub fn spread(&self) -> Option<&Expr> {
- super::child_opt(self)
- }
-}
-
-// StructPat
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
-pub struct StructPat {
- pub(crate) syntax: SyntaxNode,
-}
-unsafe impl TransparentNewType for StructPat {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
-impl AstNode for StructPat {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- STRUCT_PAT => Some(StructPat::from_repr(syntax.into_repr())),
- _ => None,
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for StructPat {
- type Owned = TreeArc<StructPat>;
- fn to_owned(&self) -> TreeArc<StructPat> { TreeArc::cast(self.syntax.to_owned()) }
-}
-
-
-impl StructPat {
- pub fn field_pat_list(&self) -> Option<&FieldPatList> {
- super::child_opt(self)
- }
-
- pub fn path(&self) -> Option<&Path> {
- super::child_opt(self)
- }
-}
-
-// TokenTree
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
-pub struct TokenTree {
- pub(crate) syntax: SyntaxNode,
-}
-unsafe impl TransparentNewType for TokenTree {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
-impl AstNode for TokenTree {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- TOKEN_TREE => Some(TokenTree::from_repr(syntax.into_repr())),
- _ => None,
- }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for TokenTree {
- type Owned = TreeArc<TokenTree>;
- fn to_owned(&self) -> TreeArc<TokenTree> { TreeArc::cast(self.syntax.to_owned()) }
}
-
-
impl TokenTree {}
-
-// TraitDef
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TraitDef {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for TraitDef {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for TraitDef {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- TRAIT_DEF => Some(TraitDef::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ TRAIT_DEF => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for TraitDef {
- type Owned = TreeArc<TraitDef>;
- fn to_owned(&self) -> TreeArc<TraitDef> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::VisibilityOwner for TraitDef {}
impl ast::NameOwner for TraitDef {}
impl ast::AttrsOwner for TraitDef {}
impl ast::TypeParamsOwner for TraitDef {}
impl ast::TypeBoundsOwner for TraitDef {}
impl TraitDef {
- pub fn item_list(&self) -> Option<&ItemList> {
- super::child_opt(self)
+ pub fn item_list(&self) -> Option<ItemList> {
+ AstChildren::new(&self.syntax).next()
+ }
+}
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct TryBlockExpr {
+ pub(crate) syntax: SyntaxNode,
+}
+impl AstNode for TryBlockExpr {
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ TRY_BLOCK_EXPR => true,
+ _ => false,
+ }
+ }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
}
}
-
-// TryExpr
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+impl TryBlockExpr {
+ pub fn body(&self) -> Option<BlockExpr> {
+ AstChildren::new(&self.syntax).next()
+ }
+}
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TryExpr {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for TryExpr {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for TryExpr {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- TRY_EXPR => Some(TryExpr::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ TRY_EXPR => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for TryExpr {
- type Owned = TreeArc<TryExpr>;
- fn to_owned(&self) -> TreeArc<TryExpr> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl TryExpr {
- pub fn expr(&self) -> Option<&Expr> {
- super::child_opt(self)
+ pub fn expr(&self) -> Option<Expr> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// TupleExpr
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TupleExpr {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for TupleExpr {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for TupleExpr {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- TUPLE_EXPR => Some(TupleExpr::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ TUPLE_EXPR => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for TupleExpr {
- type Owned = TreeArc<TupleExpr>;
- fn to_owned(&self) -> TreeArc<TupleExpr> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl TupleExpr {
- pub fn exprs(&self) -> impl Iterator<Item = &Expr> {
- super::children(self)
+ pub fn exprs(&self) -> AstChildren<Expr> {
+ AstChildren::new(&self.syntax)
}
}
-
-// TuplePat
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
-pub struct TuplePat {
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct TupleFieldDef {
+ pub(crate) syntax: SyntaxNode,
+}
+impl AstNode for TupleFieldDef {
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ TUPLE_FIELD_DEF => true,
+ _ => false,
+ }
+ }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
+}
+impl ast::VisibilityOwner for TupleFieldDef {}
+impl ast::AttrsOwner for TupleFieldDef {}
+impl TupleFieldDef {
+ pub fn type_ref(&self) -> Option<TypeRef> {
+ AstChildren::new(&self.syntax).next()
+ }
+}
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct TupleFieldDefList {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for TuplePat {
- type Repr = rowan::SyntaxNode<RaTypes>;
+impl AstNode for TupleFieldDefList {
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ TUPLE_FIELD_DEF_LIST => true,
+ _ => false,
+ }
+ }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
+}
+impl TupleFieldDefList {
+ pub fn fields(&self) -> AstChildren<TupleFieldDef> {
+ AstChildren::new(&self.syntax)
+ }
+}
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct TuplePat {
+ pub(crate) syntax: SyntaxNode,
}
-
impl AstNode for TuplePat {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- TUPLE_PAT => Some(TuplePat::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ TUPLE_PAT => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for TuplePat {
- type Owned = TreeArc<TuplePat>;
- fn to_owned(&self) -> TreeArc<TuplePat> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl TuplePat {
- pub fn args(&self) -> impl Iterator<Item = &Pat> {
- super::children(self)
+ pub fn args(&self) -> AstChildren<Pat> {
+ AstChildren::new(&self.syntax)
}
}
-
-// TupleStructPat
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TupleStructPat {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for TupleStructPat {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for TupleStructPat {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- TUPLE_STRUCT_PAT => Some(TupleStructPat::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ TUPLE_STRUCT_PAT => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for TupleStructPat {
- type Owned = TreeArc<TupleStructPat>;
- fn to_owned(&self) -> TreeArc<TupleStructPat> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl TupleStructPat {
- pub fn args(&self) -> impl Iterator<Item = &Pat> {
- super::children(self)
+ pub fn args(&self) -> AstChildren<Pat> {
+ AstChildren::new(&self.syntax)
}
-
- pub fn path(&self) -> Option<&Path> {
- super::child_opt(self)
+ pub fn path(&self) -> Option<Path> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// TupleType
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TupleType {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for TupleType {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for TupleType {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- TUPLE_TYPE => Some(TupleType::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ TUPLE_TYPE => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for TupleType {
- type Owned = TreeArc<TupleType>;
- fn to_owned(&self) -> TreeArc<TupleType> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl TupleType {
- pub fn fields(&self) -> impl Iterator<Item = &TypeRef> {
- super::children(self)
+ pub fn fields(&self) -> AstChildren<TypeRef> {
+ AstChildren::new(&self.syntax)
}
}
-
-// TypeAliasDef
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TypeAliasDef {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for TypeAliasDef {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for TypeAliasDef {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- TYPE_ALIAS_DEF => Some(TypeAliasDef::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ TYPE_ALIAS_DEF => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for TypeAliasDef {
- type Owned = TreeArc<TypeAliasDef>;
- fn to_owned(&self) -> TreeArc<TypeAliasDef> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::VisibilityOwner for TypeAliasDef {}
impl ast::NameOwner for TypeAliasDef {}
impl ast::TypeParamsOwner for TypeAliasDef {}
impl ast::DocCommentsOwner for TypeAliasDef {}
impl ast::TypeBoundsOwner for TypeAliasDef {}
impl TypeAliasDef {
- pub fn type_ref(&self) -> Option<&TypeRef> {
- super::child_opt(self)
+ pub fn type_ref(&self) -> Option<TypeRef> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// TypeArg
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TypeArg {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for TypeArg {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for TypeArg {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- TYPE_ARG => Some(TypeArg::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ TYPE_ARG => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for TypeArg {
- type Owned = TreeArc<TypeArg>;
- fn to_owned(&self) -> TreeArc<TypeArg> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl TypeArg {
- pub fn type_ref(&self) -> Option<&TypeRef> {
- super::child_opt(self)
+ pub fn type_ref(&self) -> Option<TypeRef> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// TypeArgList
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TypeArgList {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for TypeArgList {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for TypeArgList {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- TYPE_ARG_LIST => Some(TypeArgList::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ TYPE_ARG_LIST => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for TypeArgList {
- type Owned = TreeArc<TypeArgList>;
- fn to_owned(&self) -> TreeArc<TypeArgList> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl TypeArgList {
- pub fn type_args(&self) -> impl Iterator<Item = &TypeArg> {
- super::children(self)
+ pub fn type_args(&self) -> AstChildren<TypeArg> {
+ AstChildren::new(&self.syntax)
}
-
- pub fn lifetime_args(&self) -> impl Iterator<Item = &LifetimeArg> {
- super::children(self)
+ pub fn lifetime_args(&self) -> AstChildren<LifetimeArg> {
+ AstChildren::new(&self.syntax)
}
-
- pub fn assoc_type_args(&self) -> impl Iterator<Item = &AssocTypeArg> {
- super::children(self)
+ pub fn assoc_type_args(&self) -> AstChildren<AssocTypeArg> {
+ AstChildren::new(&self.syntax)
}
}
-
-// TypeBound
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TypeBound {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for TypeBound {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for TypeBound {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- TYPE_BOUND => Some(TypeBound::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ TYPE_BOUND => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for TypeBound {
- type Owned = TreeArc<TypeBound>;
- fn to_owned(&self) -> TreeArc<TypeBound> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl TypeBound {
- pub fn type_ref(&self) -> Option<&TypeRef> {
- super::child_opt(self)
+ pub fn type_ref(&self) -> Option<TypeRef> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// TypeBoundList
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TypeBoundList {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for TypeBoundList {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for TypeBoundList {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- TYPE_BOUND_LIST => Some(TypeBoundList::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ TYPE_BOUND_LIST => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for TypeBoundList {
- type Owned = TreeArc<TypeBoundList>;
- fn to_owned(&self) -> TreeArc<TypeBoundList> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl TypeBoundList {
- pub fn bounds(&self) -> impl Iterator<Item = &TypeBound> {
- super::children(self)
+ pub fn bounds(&self) -> AstChildren<TypeBound> {
+ AstChildren::new(&self.syntax)
}
}
-
-// TypeParam
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TypeParam {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for TypeParam {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for TypeParam {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- TYPE_PARAM => Some(TypeParam::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ TYPE_PARAM => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for TypeParam {
- type Owned = TreeArc<TypeParam>;
- fn to_owned(&self) -> TreeArc<TypeParam> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::NameOwner for TypeParam {}
impl ast::AttrsOwner for TypeParam {}
impl ast::TypeBoundsOwner for TypeParam {}
-impl TypeParam {}
-
-// TypeParamList
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+impl TypeParam {
+ pub fn default_type(&self) -> Option<TypeRef> {
+ AstChildren::new(&self.syntax).next()
+ }
+}
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TypeParamList {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for TypeParamList {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for TypeParamList {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- TYPE_PARAM_LIST => Some(TypeParamList::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ TYPE_PARAM_LIST => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for TypeParamList {
- type Owned = TreeArc<TypeParamList>;
- fn to_owned(&self) -> TreeArc<TypeParamList> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl TypeParamList {
- pub fn type_params(&self) -> impl Iterator<Item = &TypeParam> {
- super::children(self)
+ pub fn type_params(&self) -> AstChildren<TypeParam> {
+ AstChildren::new(&self.syntax)
}
-
- pub fn lifetime_params(&self) -> impl Iterator<Item = &LifetimeParam> {
- super::children(self)
+ pub fn lifetime_params(&self) -> AstChildren<LifetimeParam> {
+ AstChildren::new(&self.syntax)
}
}
-
-// TypeRef
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
-pub struct TypeRef {
- pub(crate) syntax: SyntaxNode,
-}
-unsafe impl TransparentNewType for TypeRef {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-pub enum TypeRefKind<'a> {
- ParenType(&'a ParenType),
- TupleType(&'a TupleType),
- NeverType(&'a NeverType),
- PathType(&'a PathType),
- PointerType(&'a PointerType),
- ArrayType(&'a ArrayType),
- SliceType(&'a SliceType),
- ReferenceType(&'a ReferenceType),
- PlaceholderType(&'a PlaceholderType),
- FnPointerType(&'a FnPointerType),
- ForType(&'a ForType),
- ImplTraitType(&'a ImplTraitType),
- DynTraitType(&'a DynTraitType),
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub enum TypeRef {
+ ParenType(ParenType),
+ TupleType(TupleType),
+ NeverType(NeverType),
+ PathType(PathType),
+ PointerType(PointerType),
+ ArrayType(ArrayType),
+ SliceType(SliceType),
+ ReferenceType(ReferenceType),
+ PlaceholderType(PlaceholderType),
+ FnPointerType(FnPointerType),
+ ForType(ForType),
+ ImplTraitType(ImplTraitType),
+ DynTraitType(DynTraitType),
}
-impl<'a> From<&'a ParenType> for &'a TypeRef {
- fn from(n: &'a ParenType) -> &'a TypeRef {
- TypeRef::cast(&n.syntax).unwrap()
+impl From<ParenType> for TypeRef {
+ fn from(node: ParenType) -> TypeRef {
+ TypeRef::ParenType(node)
}
}
-impl<'a> From<&'a TupleType> for &'a TypeRef {
- fn from(n: &'a TupleType) -> &'a TypeRef {
- TypeRef::cast(&n.syntax).unwrap()
+impl From<TupleType> for TypeRef {
+ fn from(node: TupleType) -> TypeRef {
+ TypeRef::TupleType(node)
}
}
-impl<'a> From<&'a NeverType> for &'a TypeRef {
- fn from(n: &'a NeverType) -> &'a TypeRef {
- TypeRef::cast(&n.syntax).unwrap()
+impl From<NeverType> for TypeRef {
+ fn from(node: NeverType) -> TypeRef {
+ TypeRef::NeverType(node)
}
}
-impl<'a> From<&'a PathType> for &'a TypeRef {
- fn from(n: &'a PathType) -> &'a TypeRef {
- TypeRef::cast(&n.syntax).unwrap()
+impl From<PathType> for TypeRef {
+ fn from(node: PathType) -> TypeRef {
+ TypeRef::PathType(node)
}
}
-impl<'a> From<&'a PointerType> for &'a TypeRef {
- fn from(n: &'a PointerType) -> &'a TypeRef {
- TypeRef::cast(&n.syntax).unwrap()
+impl From<PointerType> for TypeRef {
+ fn from(node: PointerType) -> TypeRef {
+ TypeRef::PointerType(node)
}
}
-impl<'a> From<&'a ArrayType> for &'a TypeRef {
- fn from(n: &'a ArrayType) -> &'a TypeRef {
- TypeRef::cast(&n.syntax).unwrap()
+impl From<ArrayType> for TypeRef {
+ fn from(node: ArrayType) -> TypeRef {
+ TypeRef::ArrayType(node)
}
}
-impl<'a> From<&'a SliceType> for &'a TypeRef {
- fn from(n: &'a SliceType) -> &'a TypeRef {
- TypeRef::cast(&n.syntax).unwrap()
+impl From<SliceType> for TypeRef {
+ fn from(node: SliceType) -> TypeRef {
+ TypeRef::SliceType(node)
}
}
-impl<'a> From<&'a ReferenceType> for &'a TypeRef {
- fn from(n: &'a ReferenceType) -> &'a TypeRef {
- TypeRef::cast(&n.syntax).unwrap()
+impl From<ReferenceType> for TypeRef {
+ fn from(node: ReferenceType) -> TypeRef {
+ TypeRef::ReferenceType(node)
}
}
-impl<'a> From<&'a PlaceholderType> for &'a TypeRef {
- fn from(n: &'a PlaceholderType) -> &'a TypeRef {
- TypeRef::cast(&n.syntax).unwrap()
+impl From<PlaceholderType> for TypeRef {
+ fn from(node: PlaceholderType) -> TypeRef {
+ TypeRef::PlaceholderType(node)
}
}
-impl<'a> From<&'a FnPointerType> for &'a TypeRef {
- fn from(n: &'a FnPointerType) -> &'a TypeRef {
- TypeRef::cast(&n.syntax).unwrap()
+impl From<FnPointerType> for TypeRef {
+ fn from(node: FnPointerType) -> TypeRef {
+ TypeRef::FnPointerType(node)
}
}
-impl<'a> From<&'a ForType> for &'a TypeRef {
- fn from(n: &'a ForType) -> &'a TypeRef {
- TypeRef::cast(&n.syntax).unwrap()
+impl From<ForType> for TypeRef {
+ fn from(node: ForType) -> TypeRef {
+ TypeRef::ForType(node)
}
}
-impl<'a> From<&'a ImplTraitType> for &'a TypeRef {
- fn from(n: &'a ImplTraitType) -> &'a TypeRef {
- TypeRef::cast(&n.syntax).unwrap()
+impl From<ImplTraitType> for TypeRef {
+ fn from(node: ImplTraitType) -> TypeRef {
+ TypeRef::ImplTraitType(node)
}
}
-impl<'a> From<&'a DynTraitType> for &'a TypeRef {
- fn from(n: &'a DynTraitType) -> &'a TypeRef {
- TypeRef::cast(&n.syntax).unwrap()
+impl From<DynTraitType> for TypeRef {
+ fn from(node: DynTraitType) -> TypeRef {
+ TypeRef::DynTraitType(node)
}
}
-
-
impl AstNode for TypeRef {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- | PAREN_TYPE
- | TUPLE_TYPE
- | NEVER_TYPE
- | PATH_TYPE
- | POINTER_TYPE
- | ARRAY_TYPE
- | SLICE_TYPE
- | REFERENCE_TYPE
- | PLACEHOLDER_TYPE
- | FN_POINTER_TYPE
- | FOR_TYPE
- | IMPL_TRAIT_TYPE
- | DYN_TRAIT_TYPE => Some(TypeRef::from_repr(syntax.into_repr())),
- _ => None,
- }
- }
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ PAREN_TYPE | TUPLE_TYPE | NEVER_TYPE | PATH_TYPE | POINTER_TYPE | ARRAY_TYPE
+ | SLICE_TYPE | REFERENCE_TYPE | PLACEHOLDER_TYPE | FN_POINTER_TYPE | FOR_TYPE
+ | IMPL_TRAIT_TYPE | DYN_TRAIT_TYPE => true,
+ _ => false,
+ }
+ }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ let res = match syntax.kind() {
+ PAREN_TYPE => TypeRef::ParenType(ParenType { syntax }),
+ TUPLE_TYPE => TypeRef::TupleType(TupleType { syntax }),
+ NEVER_TYPE => TypeRef::NeverType(NeverType { syntax }),
+ PATH_TYPE => TypeRef::PathType(PathType { syntax }),
+ POINTER_TYPE => TypeRef::PointerType(PointerType { syntax }),
+ ARRAY_TYPE => TypeRef::ArrayType(ArrayType { syntax }),
+ SLICE_TYPE => TypeRef::SliceType(SliceType { syntax }),
+ REFERENCE_TYPE => TypeRef::ReferenceType(ReferenceType { syntax }),
+ PLACEHOLDER_TYPE => TypeRef::PlaceholderType(PlaceholderType { syntax }),
+ FN_POINTER_TYPE => TypeRef::FnPointerType(FnPointerType { syntax }),
+ FOR_TYPE => TypeRef::ForType(ForType { syntax }),
+ IMPL_TRAIT_TYPE => TypeRef::ImplTraitType(ImplTraitType { syntax }),
+ DYN_TRAIT_TYPE => TypeRef::DynTraitType(DynTraitType { syntax }),
+ _ => return None,
+ };
+ Some(res)
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ match self {
+ TypeRef::ParenType(it) => &it.syntax,
+ TypeRef::TupleType(it) => &it.syntax,
+ TypeRef::NeverType(it) => &it.syntax,
+ TypeRef::PathType(it) => &it.syntax,
+ TypeRef::PointerType(it) => &it.syntax,
+ TypeRef::ArrayType(it) => &it.syntax,
+ TypeRef::SliceType(it) => &it.syntax,
+ TypeRef::ReferenceType(it) => &it.syntax,
+ TypeRef::PlaceholderType(it) => &it.syntax,
+ TypeRef::FnPointerType(it) => &it.syntax,
+ TypeRef::ForType(it) => &it.syntax,
+ TypeRef::ImplTraitType(it) => &it.syntax,
+ TypeRef::DynTraitType(it) => &it.syntax,
+ }
+ }
}
-
-impl ToOwned for TypeRef {
- type Owned = TreeArc<TypeRef>;
- fn to_owned(&self) -> TreeArc<TypeRef> { TreeArc::cast(self.syntax.to_owned()) }
+impl TypeRef {}
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct UnionDef {
+ pub(crate) syntax: SyntaxNode,
}
-
-impl TypeRef {
- pub fn kind(&self) -> TypeRefKind {
- match self.syntax.kind() {
- PAREN_TYPE => TypeRefKind::ParenType(ParenType::cast(&self.syntax).unwrap()),
- TUPLE_TYPE => TypeRefKind::TupleType(TupleType::cast(&self.syntax).unwrap()),
- NEVER_TYPE => TypeRefKind::NeverType(NeverType::cast(&self.syntax).unwrap()),
- PATH_TYPE => TypeRefKind::PathType(PathType::cast(&self.syntax).unwrap()),
- POINTER_TYPE => TypeRefKind::PointerType(PointerType::cast(&self.syntax).unwrap()),
- ARRAY_TYPE => TypeRefKind::ArrayType(ArrayType::cast(&self.syntax).unwrap()),
- SLICE_TYPE => TypeRefKind::SliceType(SliceType::cast(&self.syntax).unwrap()),
- REFERENCE_TYPE => TypeRefKind::ReferenceType(ReferenceType::cast(&self.syntax).unwrap()),
- PLACEHOLDER_TYPE => TypeRefKind::PlaceholderType(PlaceholderType::cast(&self.syntax).unwrap()),
- FN_POINTER_TYPE => TypeRefKind::FnPointerType(FnPointerType::cast(&self.syntax).unwrap()),
- FOR_TYPE => TypeRefKind::ForType(ForType::cast(&self.syntax).unwrap()),
- IMPL_TRAIT_TYPE => TypeRefKind::ImplTraitType(ImplTraitType::cast(&self.syntax).unwrap()),
- DYN_TRAIT_TYPE => TypeRefKind::DynTraitType(DynTraitType::cast(&self.syntax).unwrap()),
- _ => unreachable!(),
+impl AstNode for UnionDef {
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ UNION_DEF => true,
+ _ => false,
}
}
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-impl TypeRef {}
-
-// UseItem
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+impl ast::VisibilityOwner for UnionDef {}
+impl ast::NameOwner for UnionDef {}
+impl ast::TypeParamsOwner for UnionDef {}
+impl ast::AttrsOwner for UnionDef {}
+impl ast::DocCommentsOwner for UnionDef {}
+impl UnionDef {
+ pub fn record_field_def_list(&self) -> Option<RecordFieldDefList> {
+ AstChildren::new(&self.syntax).next()
+ }
+}
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct UseItem {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for UseItem {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for UseItem {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- USE_ITEM => Some(UseItem::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ USE_ITEM => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for UseItem {
- type Owned = TreeArc<UseItem>;
- fn to_owned(&self) -> TreeArc<UseItem> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::AttrsOwner for UseItem {}
impl UseItem {
- pub fn use_tree(&self) -> Option<&UseTree> {
- super::child_opt(self)
+ pub fn use_tree(&self) -> Option<UseTree> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// UseTree
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct UseTree {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for UseTree {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for UseTree {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- USE_TREE => Some(UseTree::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ USE_TREE => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for UseTree {
- type Owned = TreeArc<UseTree>;
- fn to_owned(&self) -> TreeArc<UseTree> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl UseTree {
- pub fn path(&self) -> Option<&Path> {
- super::child_opt(self)
+ pub fn path(&self) -> Option<Path> {
+ AstChildren::new(&self.syntax).next()
}
-
- pub fn use_tree_list(&self) -> Option<&UseTreeList> {
- super::child_opt(self)
+ pub fn use_tree_list(&self) -> Option<UseTreeList> {
+ AstChildren::new(&self.syntax).next()
}
-
- pub fn alias(&self) -> Option<&Alias> {
- super::child_opt(self)
+ pub fn alias(&self) -> Option<Alias> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// UseTreeList
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct UseTreeList {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for UseTreeList {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for UseTreeList {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- USE_TREE_LIST => Some(UseTreeList::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ USE_TREE_LIST => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for UseTreeList {
- type Owned = TreeArc<UseTreeList>;
- fn to_owned(&self) -> TreeArc<UseTreeList> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl UseTreeList {
- pub fn use_trees(&self) -> impl Iterator<Item = &UseTree> {
- super::children(self)
+ pub fn use_trees(&self) -> AstChildren<UseTree> {
+ AstChildren::new(&self.syntax)
}
}
-
-// Visibility
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Visibility {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for Visibility {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for Visibility {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- VISIBILITY => Some(Visibility::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ VISIBILITY => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for Visibility {
- type Owned = TreeArc<Visibility>;
- fn to_owned(&self) -> TreeArc<Visibility> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl Visibility {}
-
-// WhereClause
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct WhereClause {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for WhereClause {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for WhereClause {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- WHERE_CLAUSE => Some(WhereClause::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ WHERE_CLAUSE => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for WhereClause {
- type Owned = TreeArc<WhereClause>;
- fn to_owned(&self) -> TreeArc<WhereClause> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl WhereClause {
- pub fn predicates(&self) -> impl Iterator<Item = &WherePred> {
- super::children(self)
+ pub fn predicates(&self) -> AstChildren<WherePred> {
+ AstChildren::new(&self.syntax)
}
}
-
-// WherePred
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct WherePred {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for WherePred {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for WherePred {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- WHERE_PRED => Some(WherePred::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ WHERE_PRED => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for WherePred {
- type Owned = TreeArc<WherePred>;
- fn to_owned(&self) -> TreeArc<WherePred> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::TypeBoundsOwner for WherePred {}
impl WherePred {
- pub fn type_ref(&self) -> Option<&TypeRef> {
- super::child_opt(self)
+ pub fn type_ref(&self) -> Option<TypeRef> {
+ AstChildren::new(&self.syntax).next()
}
}
-
-// WhileExpr
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct WhileExpr {
pub(crate) syntax: SyntaxNode,
}
-unsafe impl TransparentNewType for WhileExpr {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
impl AstNode for WhileExpr {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- WHILE_EXPR => Some(WhileExpr::from_repr(syntax.into_repr())),
- _ => None,
+ fn can_cast(kind: SyntaxKind) -> bool {
+ match kind {
+ WHILE_EXPR => true,
+ _ => false,
}
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for WhileExpr {
- type Owned = TreeArc<WhileExpr>;
- fn to_owned(&self) -> TreeArc<WhileExpr> { TreeArc::cast(self.syntax.to_owned()) }
+ fn cast(syntax: SyntaxNode) -> Option<Self> {
+ if Self::can_cast(syntax.kind()) {
+ Some(Self { syntax })
+ } else {
+ None
+ }
+ }
+ fn syntax(&self) -> &SyntaxNode {
+ &self.syntax
+ }
}
-
-
impl ast::LoopBodyOwner for WhileExpr {}
impl WhileExpr {
- pub fn condition(&self) -> Option<&Condition> {
- super::child_opt(self)
- }
-}
-
-// Whitespace
-#[derive(Debug, PartialEq, Eq, Hash)]
-#[repr(transparent)]
-pub struct Whitespace {
- pub(crate) syntax: SyntaxNode,
-}
-unsafe impl TransparentNewType for Whitespace {
- type Repr = rowan::SyntaxNode<RaTypes>;
-}
-
-impl AstNode for Whitespace {
- fn cast(syntax: &SyntaxNode) -> Option<&Self> {
- match syntax.kind() {
- WHITESPACE => Some(Whitespace::from_repr(syntax.into_repr())),
- _ => None,
- }
+ pub fn condition(&self) -> Option<Condition> {
+ AstChildren::new(&self.syntax).next()
}
- fn syntax(&self) -> &SyntaxNode { &self.syntax }
-}
-
-impl ToOwned for Whitespace {
- type Owned = TreeArc<Whitespace>;
- fn to_owned(&self) -> TreeArc<Whitespace> { TreeArc::cast(self.syntax.to_owned()) }
}
-
-
-impl ast::AstToken for Whitespace {}
-impl Whitespace {}
-