rust-analyzer/crates/ra_syntax/src/ast/generated.rs

4013 lines
100 KiB
Rust
Raw Normal View History

//! Generated file, do not edit by hand, see `crate/ra_tools/src/codegen`
2018-10-15 16:55:32 +00:00
use crate::{
2019-08-18 20:36:22 +00:00
ast::{self, AstChildren, AstNode},
SyntaxKind::{self, *},
SyntaxNode,
2018-08-09 14:43:39 +00:00
};
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-02-01 23:18:10 +00:00
pub struct Alias {
pub(crate) syntax: SyntaxNode,
}
impl AstNode for Alias {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
ALIAS => true,
_ => false,
2019-02-01 23:18:10 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
2019-02-01 23:18:10 +00:00
}
impl ast::NameOwner for Alias {}
impl Alias {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct ArgList {
pub(crate) syntax: SyntaxNode,
2018-08-28 20:59:57 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for ArgList {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
ARG_LIST => true,
_ => false,
2018-08-28 20:59:57 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl ArgList {
2019-08-18 20:36:22 +00:00
pub fn args(&self) -> AstChildren<Expr> {
AstChildren::new(&self.syntax)
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct ArrayExpr {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for ArrayExpr {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
ARRAY_EXPR => true,
_ => false,
2018-08-25 10:42:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-13 13:46:10 +00:00
impl ArrayExpr {
2019-08-18 20:36:22 +00:00
pub fn exprs(&self) -> AstChildren<Expr> {
AstChildren::new(&self.syntax)
2019-01-13 13:46:10 +00:00
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct ArrayType {
pub(crate) syntax: SyntaxNode,
2018-08-14 09:38:20 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for ArrayType {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
ARRAY_TYPE => true,
_ => false,
2018-08-14 09:38:20 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl ArrayType {
2019-07-18 16:23:05 +00:00
pub fn type_ref(&self) -> Option<TypeRef> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
2019-07-18 16:23:05 +00:00
pub fn expr(&self) -> Option<Expr> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct AssocTypeArg {
pub(crate) syntax: SyntaxNode,
}
impl AstNode for AssocTypeArg {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
ASSOC_TYPE_ARG => true,
_ => false,
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
impl AssocTypeArg {
2019-07-18 16:23:05 +00:00
pub fn name_ref(&self) -> Option<NameRef> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
2019-07-18 16:23:05 +00:00
pub fn type_ref(&self) -> Option<TypeRef> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct Attr {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for Attr {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
ATTR => true,
_ => false,
2018-08-16 09:51:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl Attr {
2019-09-29 20:44:33 +00:00
pub fn path(&self) -> Option<Path> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
2019-09-29 20:44:33 +00:00
pub fn input(&self) -> Option<AttrInput> {
AstChildren::new(&self.syntax).next()
}
}
2019-07-20 10:35:49 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-09-29 20:44:33 +00:00
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,
}
}
}
2019-09-29 20:44:33 +00:00
impl AttrInput {}
2019-07-20 10:35:49 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct AwaitExpr {
pub(crate) syntax: SyntaxNode,
}
impl AstNode for AwaitExpr {
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
AWAIT_EXPR => true,
_ => false,
}
}
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-20 10:35:49 +00:00
}
}
impl AwaitExpr {
pub fn expr(&self) -> Option<Expr> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2019-07-20 10:35:49 +00:00
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct BinExpr {
pub(crate) syntax: SyntaxNode,
2018-08-25 10:42:40 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for BinExpr {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
BIN_EXPR => true,
_ => false,
2018-08-25 10:42:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl BinExpr {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct BindPat {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for BindPat {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
BIND_PAT => true,
_ => false,
2018-08-26 09:09:28 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl ast::NameOwner for BindPat {}
impl BindPat {
2019-07-18 16:23:05 +00:00
pub fn pat(&self) -> Option<Pat> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct Block {
pub(crate) syntax: SyntaxNode,
2018-08-25 10:42:40 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for Block {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
BLOCK => true,
_ => false,
2018-08-25 10:42:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
impl ast::AttrsOwner for Block {}
2019-01-07 13:16:02 +00:00
impl Block {
2019-08-18 20:36:22 +00:00
pub fn statements(&self) -> AstChildren<Stmt> {
AstChildren::new(&self.syntax)
2018-08-26 09:09:28 +00:00
}
2019-07-18 16:23:05 +00:00
pub fn expr(&self) -> Option<Expr> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-08-27 07:12:28 +00:00
}
2018-08-26 09:09:28 +00:00
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct BlockExpr {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for BlockExpr {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
BLOCK_EXPR => true,
_ => false,
2018-08-25 10:42:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl BlockExpr {
2019-07-18 16:23:05 +00:00
pub fn block(&self) -> Option<Block> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-09-11 15:53:41 +00:00
pub struct BoxExpr {
pub(crate) syntax: SyntaxNode,
}
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 BoxExpr {
pub fn expr(&self) -> Option<Expr> {
AstChildren::new(&self.syntax).next()
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-08-23 20:04:58 +00:00
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
}
}
impl BoxPat {
pub fn pat(&self) -> Option<Pat> {
AstChildren::new(&self.syntax).next()
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct BreakExpr {
pub(crate) syntax: SyntaxNode,
2018-08-25 10:42:40 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for BreakExpr {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
BREAK_EXPR => true,
_ => false,
2018-08-25 10:42:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl BreakExpr {
2019-07-18 16:23:05 +00:00
pub fn expr(&self) -> Option<Expr> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2019-01-05 15:32:07 +00:00
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct CallExpr {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for CallExpr {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
CALL_EXPR => true,
_ => false,
2018-08-25 10:42:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl ast::ArgListOwner for CallExpr {}
impl CallExpr {
2019-07-18 16:23:05 +00:00
pub fn expr(&self) -> Option<Expr> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-08-28 20:59:57 +00:00
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct CastExpr {
pub(crate) syntax: SyntaxNode,
2018-08-25 10:42:40 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for CastExpr {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
CAST_EXPR => true,
_ => false,
2018-08-25 10:42:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl CastExpr {
2019-07-18 16:23:05 +00:00
pub fn expr(&self) -> Option<Expr> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-12-20 20:56:28 +00:00
}
2019-07-18 16:23:05 +00:00
pub fn type_ref(&self) -> Option<TypeRef> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-12-20 20:56:28 +00:00
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct Condition {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for Condition {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
CONDITION => true,
_ => false,
2018-08-27 09:22:09 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl Condition {
2019-07-18 16:23:05 +00:00
pub fn pat(&self) -> Option<Pat> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-08-27 09:22:09 +00:00
}
2019-07-18 16:23:05 +00:00
pub fn expr(&self) -> Option<Expr> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-08-27 09:22:09 +00:00
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct ConstDef {
pub(crate) syntax: SyntaxNode,
2018-08-11 08:03:22 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for ConstDef {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
CONST_DEF => true,
_ => false,
2018-08-11 08:03:22 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
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 {
2019-07-18 16:23:05 +00:00
pub fn body(&self) -> Option<Expr> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct ContinueExpr {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for ContinueExpr {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
CONTINUE_EXPR => true,
_ => false,
2018-08-25 10:42:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl ContinueExpr {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct DotDotPat {
pub(crate) syntax: SyntaxNode,
}
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)]
2019-01-07 13:16:02 +00:00
pub struct DynTraitType {
pub(crate) syntax: SyntaxNode,
2018-08-14 09:38:20 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for DynTraitType {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
DYN_TRAIT_TYPE => true,
_ => false,
2018-08-14 09:38:20 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-03-31 07:56:48 +00:00
impl ast::TypeBoundsOwner for DynTraitType {}
2019-01-07 13:16:02 +00:00
impl DynTraitType {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct EnumDef {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for EnumDef {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
ENUM_DEF => true,
_ => false,
2018-08-11 07:56:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
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 {
2019-07-18 16:23:05 +00:00
pub fn variant_list(&self) -> Option<EnumVariantList> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct EnumVariant {
pub(crate) syntax: SyntaxNode,
}
2019-01-07 13:16:02 +00:00
impl AstNode for EnumVariant {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
ENUM_VARIANT => true,
_ => false,
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl ast::NameOwner for EnumVariant {}
2019-01-23 20:59:19 +00:00
impl ast::DocCommentsOwner for EnumVariant {}
2019-02-05 22:05:46 +00:00
impl ast::AttrsOwner for EnumVariant {}
2019-01-07 13:16:02 +00:00
impl EnumVariant {
2019-07-18 16:23:05 +00:00
pub fn expr(&self) -> Option<Expr> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct EnumVariantList {
pub(crate) syntax: SyntaxNode,
}
2019-01-07 13:16:02 +00:00
impl AstNode for EnumVariantList {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
ENUM_VARIANT_LIST => true,
_ => false,
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl EnumVariantList {
2019-08-18 20:36:22 +00:00
pub fn variants(&self) -> AstChildren<EnumVariant> {
AstChildren::new(&self.syntax)
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Expr {
2019-07-18 16:23:05 +00:00
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),
2019-08-23 12:55:21 +00:00
RecordLit(RecordLit),
2019-07-18 16:23:05 +00:00
CallExpr(CallExpr),
IndexExpr(IndexExpr),
MethodCallExpr(MethodCallExpr),
FieldExpr(FieldExpr),
2019-07-20 10:35:49 +00:00
AwaitExpr(AwaitExpr),
2019-07-18 16:23:05 +00:00
TryExpr(TryExpr),
TryBlockExpr(TryBlockExpr),
CastExpr(CastExpr),
RefExpr(RefExpr),
PrefixExpr(PrefixExpr),
RangeExpr(RangeExpr),
BinExpr(BinExpr),
Literal(Literal),
MacroCall(MacroCall),
2019-09-11 15:53:41 +00:00
BoxExpr(BoxExpr),
2019-01-07 13:16:02 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<TupleExpr> for Expr {
2019-08-18 20:36:22 +00:00
fn from(node: TupleExpr) -> Expr {
Expr::TupleExpr(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<ArrayExpr> for Expr {
2019-08-18 20:36:22 +00:00
fn from(node: ArrayExpr) -> Expr {
Expr::ArrayExpr(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<ParenExpr> for Expr {
2019-08-18 20:36:22 +00:00
fn from(node: ParenExpr) -> Expr {
Expr::ParenExpr(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<PathExpr> for Expr {
2019-08-18 20:36:22 +00:00
fn from(node: PathExpr) -> Expr {
Expr::PathExpr(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<LambdaExpr> for Expr {
2019-08-18 20:36:22 +00:00
fn from(node: LambdaExpr) -> Expr {
Expr::LambdaExpr(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<IfExpr> for Expr {
2019-08-18 20:36:22 +00:00
fn from(node: IfExpr) -> Expr {
Expr::IfExpr(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<LoopExpr> for Expr {
2019-08-18 20:36:22 +00:00
fn from(node: LoopExpr) -> Expr {
Expr::LoopExpr(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<ForExpr> for Expr {
2019-08-18 20:36:22 +00:00
fn from(node: ForExpr) -> Expr {
Expr::ForExpr(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<WhileExpr> for Expr {
2019-08-18 20:36:22 +00:00
fn from(node: WhileExpr) -> Expr {
Expr::WhileExpr(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<ContinueExpr> for Expr {
2019-08-18 20:36:22 +00:00
fn from(node: ContinueExpr) -> Expr {
Expr::ContinueExpr(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<BreakExpr> for Expr {
2019-08-18 20:36:22 +00:00
fn from(node: BreakExpr) -> Expr {
Expr::BreakExpr(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<Label> for Expr {
2019-08-18 20:36:22 +00:00
fn from(node: Label) -> Expr {
Expr::Label(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<BlockExpr> for Expr {
2019-08-18 20:36:22 +00:00
fn from(node: BlockExpr) -> Expr {
Expr::BlockExpr(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<ReturnExpr> for Expr {
2019-08-18 20:36:22 +00:00
fn from(node: ReturnExpr) -> Expr {
Expr::ReturnExpr(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<MatchExpr> for Expr {
2019-08-18 20:36:22 +00:00
fn from(node: MatchExpr) -> Expr {
Expr::MatchExpr(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-08-23 12:55:21 +00:00
impl From<RecordLit> for Expr {
fn from(node: RecordLit) -> Expr {
Expr::RecordLit(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<CallExpr> for Expr {
2019-08-18 20:36:22 +00:00
fn from(node: CallExpr) -> Expr {
Expr::CallExpr(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<IndexExpr> for Expr {
2019-08-18 20:36:22 +00:00
fn from(node: IndexExpr) -> Expr {
Expr::IndexExpr(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<MethodCallExpr> for Expr {
2019-08-18 20:36:22 +00:00
fn from(node: MethodCallExpr) -> Expr {
Expr::MethodCallExpr(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<FieldExpr> for Expr {
2019-08-18 20:36:22 +00:00
fn from(node: FieldExpr) -> Expr {
Expr::FieldExpr(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-20 10:35:49 +00:00
impl From<AwaitExpr> for Expr {
2019-08-18 20:36:22 +00:00
fn from(node: AwaitExpr) -> Expr {
Expr::AwaitExpr(node)
2019-08-18 20:36:22 +00:00
}
2019-07-20 10:35:49 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<TryExpr> for Expr {
2019-08-18 20:36:22 +00:00
fn from(node: TryExpr) -> Expr {
Expr::TryExpr(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<TryBlockExpr> for Expr {
2019-08-18 20:36:22 +00:00
fn from(node: TryBlockExpr) -> Expr {
Expr::TryBlockExpr(node)
2019-08-18 20:36:22 +00:00
}
2019-06-06 11:36:16 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<CastExpr> for Expr {
2019-08-18 20:36:22 +00:00
fn from(node: CastExpr) -> Expr {
Expr::CastExpr(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<RefExpr> for Expr {
2019-08-18 20:36:22 +00:00
fn from(node: RefExpr) -> Expr {
Expr::RefExpr(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<PrefixExpr> for Expr {
2019-08-18 20:36:22 +00:00
fn from(node: PrefixExpr) -> Expr {
Expr::PrefixExpr(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<RangeExpr> for Expr {
2019-08-18 20:36:22 +00:00
fn from(node: RangeExpr) -> Expr {
Expr::RangeExpr(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<BinExpr> for Expr {
2019-08-18 20:36:22 +00:00
fn from(node: BinExpr) -> Expr {
Expr::BinExpr(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<Literal> for Expr {
2019-08-18 20:36:22 +00:00
fn from(node: Literal) -> Expr {
Expr::Literal(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<MacroCall> for Expr {
2019-08-18 20:36:22 +00:00
fn from(node: MacroCall) -> Expr {
Expr::MacroCall(node)
}
}
2019-09-11 15:53:41 +00:00
impl From<BoxExpr> for Expr {
fn from(node: BoxExpr) -> Expr {
Expr::BoxExpr(node)
}
}
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
2019-08-23 12:55:21 +00:00
| BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | RECORD_LIT | CALL_EXPR | INDEX_EXPR
| METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | TRY_BLOCK_EXPR
2019-09-11 15:53:41 +00:00
| 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 }),
2019-08-23 12:55:21 +00:00
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 }),
2019-09-11 15:53:41 +00:00
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,
2019-08-23 12:55:21 +00:00
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,
2019-09-11 15:53:41 +00:00
Expr::BoxExpr(it) => &it.syntax,
2019-01-07 13:16:02 +00:00
}
}
}
impl Expr {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct ExprStmt {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for ExprStmt {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
EXPR_STMT => true,
_ => false,
2018-08-27 07:01:31 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl ExprStmt {
2019-07-18 16:23:05 +00:00
pub fn expr(&self) -> Option<Expr> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct ExternCrateItem {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for ExternCrateItem {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
EXTERN_CRATE_ITEM => true,
_ => false,
2018-08-28 08:12:42 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
impl ast::AttrsOwner for ExternCrateItem {}
impl ExternCrateItem {
2019-07-18 16:23:05 +00:00
pub fn name_ref(&self) -> Option<NameRef> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
2019-07-18 16:23:05 +00:00
pub fn alias(&self) -> Option<Alias> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct FieldExpr {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for FieldExpr {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
FIELD_EXPR => true,
_ => false,
2018-08-25 10:42:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl FieldExpr {
2019-07-18 16:23:05 +00:00
pub fn expr(&self) -> Option<Expr> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-12-25 12:54:38 +00:00
}
2019-07-18 16:23:05 +00:00
pub fn name_ref(&self) -> Option<NameRef> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-12-25 12:54:38 +00:00
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct FnDef {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for FnDef {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
FN_DEF => true,
_ => false,
2018-08-09 14:43:39 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
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 {
2019-07-18 16:23:05 +00:00
pub fn param_list(&self) -> Option<ParamList> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-08-26 09:09:28 +00:00
}
2019-09-02 16:42:14 +00:00
pub fn body(&self) -> Option<BlockExpr> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-08-27 07:01:31 +00:00
}
2019-07-18 16:23:05 +00:00
pub fn ret_type(&self) -> Option<RetType> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-08-28 18:11:17 +00:00
}
2018-08-26 09:09:28 +00:00
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct FnPointerType {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for FnPointerType {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
FN_POINTER_TYPE => true,
_ => false,
2018-08-14 09:38:20 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl FnPointerType {
2019-07-18 16:23:05 +00:00
pub fn param_list(&self) -> Option<ParamList> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
2019-07-18 16:23:05 +00:00
pub fn ret_type(&self) -> Option<RetType> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct ForExpr {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for ForExpr {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
FOR_EXPR => true,
_ => false,
2018-08-25 10:42:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl ast::LoopBodyOwner for ForExpr {}
impl ForExpr {
2019-07-18 16:23:05 +00:00
pub fn pat(&self) -> Option<Pat> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-08-27 19:03:19 +00:00
}
2019-07-18 16:23:05 +00:00
pub fn iterable(&self) -> Option<Expr> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-08-27 19:03:19 +00:00
}
2018-08-27 09:22:09 +00:00
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct ForType {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for ForType {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
FOR_TYPE => true,
_ => false,
2018-08-14 09:38:20 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl ForType {
2019-07-18 16:23:05 +00:00
pub fn type_ref(&self) -> Option<TypeRef> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct IfExpr {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for IfExpr {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
IF_EXPR => true,
_ => false,
2018-08-25 10:42:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl IfExpr {
2019-07-18 16:23:05 +00:00
pub fn condition(&self) -> Option<Condition> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct ImplBlock {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for ImplBlock {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
IMPL_BLOCK => true,
_ => false,
2018-08-14 08:20:09 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-02-16 20:19:24 +00:00
impl ast::TypeParamsOwner for ImplBlock {}
2019-04-14 22:03:54 +00:00
impl ast::AttrsOwner for ImplBlock {}
2019-01-07 13:16:02 +00:00
impl ImplBlock {
2019-07-18 16:23:05 +00:00
pub fn item_list(&self) -> Option<ItemList> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ImplItem {
2019-07-18 16:23:05 +00:00
FnDef(FnDef),
TypeAliasDef(TypeAliasDef),
ConstDef(ConstDef),
}
2019-07-18 16:23:05 +00:00
impl From<FnDef> for ImplItem {
2019-08-18 20:36:22 +00:00
fn from(node: FnDef) -> ImplItem {
ImplItem::FnDef(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<TypeAliasDef> for ImplItem {
2019-08-18 20:36:22 +00:00
fn from(node: TypeAliasDef) -> ImplItem {
ImplItem::TypeAliasDef(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<ConstDef> for ImplItem {
2019-08-18 20:36:22 +00:00
fn from(node: ConstDef) -> ImplItem {
ImplItem::ConstDef(node)
2019-08-18 20:36:22 +00:00
}
}
impl AstNode for ImplItem {
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true,
_ => false,
}
}
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 {}
2019-01-07 13:16:02 +00:00
impl ImplItem {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct ImplTraitType {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for ImplTraitType {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
IMPL_TRAIT_TYPE => true,
_ => false,
2018-08-14 09:38:20 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-03-31 07:56:48 +00:00
impl ast::TypeBoundsOwner for ImplTraitType {}
2019-01-07 13:16:02 +00:00
impl ImplTraitType {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct IndexExpr {
pub(crate) syntax: SyntaxNode,
2018-08-25 10:42:40 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for IndexExpr {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
INDEX_EXPR => true,
_ => false,
2018-08-25 10:42:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl IndexExpr {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct ItemList {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for ItemList {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
ITEM_LIST => true,
_ => false,
2018-09-03 12:10:06 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl ast::FnDefOwner for ItemList {}
impl ast::ModuleItemOwner for ItemList {}
impl ItemList {
2019-08-18 20:36:22 +00:00
pub fn impl_items(&self) -> AstChildren<ImplItem> {
AstChildren::new(&self.syntax)
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct Label {
pub(crate) syntax: SyntaxNode,
2018-08-25 10:42:40 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for Label {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
LABEL => true,
_ => false,
2018-08-25 10:42:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl Label {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct LambdaExpr {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for LambdaExpr {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
LAMBDA_EXPR => true,
_ => false,
2018-08-25 10:42:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl LambdaExpr {
2019-07-18 16:23:05 +00:00
pub fn param_list(&self) -> Option<ParamList> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-08-28 20:59:57 +00:00
}
2019-07-18 16:23:05 +00:00
pub fn body(&self) -> Option<Expr> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-08-28 20:59:57 +00:00
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct LetStmt {
pub(crate) syntax: SyntaxNode,
2018-08-26 09:09:28 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for LetStmt {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
LET_STMT => true,
_ => false,
2018-08-26 09:09:28 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
impl ast::TypeAscriptionOwner for LetStmt {}
2019-01-07 13:16:02 +00:00
impl LetStmt {
2019-07-18 16:23:05 +00:00
pub fn pat(&self) -> Option<Pat> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-08-26 09:09:28 +00:00
}
2019-07-18 16:23:05 +00:00
pub fn initializer(&self) -> Option<Expr> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-08-27 07:01:31 +00:00
}
2018-08-26 09:09:28 +00:00
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct LifetimeArg {
pub(crate) syntax: SyntaxNode,
}
impl AstNode for LifetimeArg {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
LIFETIME_ARG => true,
_ => false,
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-03-30 10:25:53 +00:00
impl LifetimeArg {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct LifetimeParam {
pub(crate) syntax: SyntaxNode,
2018-08-28 20:59:57 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for LifetimeParam {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
LIFETIME_PARAM => true,
_ => false,
2018-08-28 20:59:57 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
impl ast::AttrsOwner for LifetimeParam {}
2019-03-30 10:25:53 +00:00
impl LifetimeParam {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct Literal {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for Literal {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
LITERAL => true,
_ => false,
2018-08-28 11:21:37 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-03-30 10:25:53 +00:00
impl Literal {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct LiteralPat {
pub(crate) syntax: SyntaxNode,
}
impl AstNode for LiteralPat {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
LITERAL_PAT => true,
_ => false,
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
impl LiteralPat {
2019-07-18 16:23:05 +00:00
pub fn literal(&self) -> Option<Literal> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct LoopExpr {
pub(crate) syntax: SyntaxNode,
2018-08-25 10:42:40 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for LoopExpr {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
LOOP_EXPR => true,
_ => false,
2018-08-25 10:42:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl ast::LoopBodyOwner for LoopExpr {}
impl LoopExpr {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct MacroCall {
pub(crate) syntax: SyntaxNode,
2018-12-28 10:27:30 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for MacroCall {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
MACRO_CALL => true,
_ => false,
2018-12-28 10:27:30 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-02-11 16:23:13 +00:00
impl ast::NameOwner for MacroCall {}
impl ast::AttrsOwner for MacroCall {}
2019-04-24 20:16:50 +00:00
impl ast::DocCommentsOwner for MacroCall {}
2019-01-07 13:16:02 +00:00
impl MacroCall {
2019-07-18 16:23:05 +00:00
pub fn token_tree(&self) -> Option<TokenTree> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-12-28 10:27:30 +00:00
}
2019-07-18 16:23:05 +00:00
pub fn path(&self) -> Option<Path> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-12-28 13:59:58 +00:00
}
2018-12-28 10:27:30 +00:00
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct MacroItems {
pub(crate) syntax: SyntaxNode,
}
impl AstNode for MacroItems {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
MACRO_ITEMS => true,
_ => false,
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
impl ast::ModuleItemOwner for MacroItems {}
impl ast::FnDefOwner for MacroItems {}
impl MacroItems {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct MacroStmts {
pub(crate) syntax: SyntaxNode,
}
impl AstNode for MacroStmts {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
MACRO_STMTS => true,
_ => false,
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
impl MacroStmts {
2019-08-18 20:36:22 +00:00
pub fn statements(&self) -> AstChildren<Stmt> {
AstChildren::new(&self.syntax)
}
2019-07-18 16:23:05 +00:00
pub fn expr(&self) -> Option<Expr> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct MatchArm {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for MatchArm {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
MATCH_ARM => true,
_ => false,
2018-08-25 10:42:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
impl ast::AttrsOwner for MatchArm {}
2019-01-07 13:16:02 +00:00
impl MatchArm {
2019-08-18 20:36:22 +00:00
pub fn pats(&self) -> AstChildren<Pat> {
AstChildren::new(&self.syntax)
2018-09-02 22:51:46 +00:00
}
2019-07-18 16:23:05 +00:00
pub fn guard(&self) -> Option<MatchGuard> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-09-02 22:51:46 +00:00
}
2019-07-18 16:23:05 +00:00
pub fn expr(&self) -> Option<Expr> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-09-02 22:51:46 +00:00
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct MatchArmList {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for MatchArmList {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
MATCH_ARM_LIST => true,
_ => false,
2018-08-25 10:42:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
impl ast::AttrsOwner for MatchArmList {}
2019-01-07 13:16:02 +00:00
impl MatchArmList {
2019-08-18 20:36:22 +00:00
pub fn arms(&self) -> AstChildren<MatchArm> {
AstChildren::new(&self.syntax)
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct MatchExpr {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for MatchExpr {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
MATCH_EXPR => true,
_ => false,
2018-08-25 10:42:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl MatchExpr {
2019-07-18 16:23:05 +00:00
pub fn expr(&self) -> Option<Expr> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-09-02 22:51:46 +00:00
}
2019-07-18 16:23:05 +00:00
pub fn match_arm_list(&self) -> Option<MatchArmList> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-09-02 22:51:46 +00:00
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct MatchGuard {
pub(crate) syntax: SyntaxNode,
2018-08-25 10:42:40 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for MatchGuard {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
MATCH_GUARD => true,
_ => false,
2018-08-25 10:42:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-28 22:06:11 +00:00
impl MatchGuard {
2019-07-18 16:23:05 +00:00
pub fn expr(&self) -> Option<Expr> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2019-01-28 22:06:11 +00:00
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct MethodCallExpr {
pub(crate) syntax: SyntaxNode,
2018-08-25 10:42:40 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for MethodCallExpr {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
METHOD_CALL_EXPR => true,
_ => false,
2018-08-25 10:42:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl ast::ArgListOwner for MethodCallExpr {}
impl MethodCallExpr {
2019-07-18 16:23:05 +00:00
pub fn expr(&self) -> Option<Expr> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-09-02 23:01:43 +00:00
}
2019-07-18 16:23:05 +00:00
pub fn name_ref(&self) -> Option<NameRef> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-12-25 14:15:40 +00:00
}
2019-07-18 16:23:05 +00:00
pub fn type_arg_list(&self) -> Option<TypeArgList> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2019-02-16 22:05:57 +00:00
}
2018-09-02 23:01:43 +00:00
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct Module {
pub(crate) syntax: SyntaxNode,
2018-08-11 08:03:22 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for Module {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
MODULE => true,
_ => false,
2018-08-11 08:03:22 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl ast::VisibilityOwner for Module {}
impl ast::NameOwner for Module {}
impl ast::AttrsOwner for Module {}
impl ast::DocCommentsOwner for Module {}
impl Module {
2019-07-18 16:23:05 +00:00
pub fn item_list(&self) -> Option<ItemList> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-08-21 15:30:10 +00:00
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ModuleItem {
2019-07-18 16:23:05 +00:00
StructDef(StructDef),
EnumDef(EnumDef),
FnDef(FnDef),
TraitDef(TraitDef),
TypeAliasDef(TypeAliasDef),
ImplBlock(ImplBlock),
UseItem(UseItem),
ExternCrateItem(ExternCrateItem),
ConstDef(ConstDef),
StaticDef(StaticDef),
Module(Module),
2019-01-07 13:16:02 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<StructDef> for ModuleItem {
2019-08-18 20:36:22 +00:00
fn from(node: StructDef) -> ModuleItem {
ModuleItem::StructDef(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<EnumDef> for ModuleItem {
2019-08-18 20:36:22 +00:00
fn from(node: EnumDef) -> ModuleItem {
ModuleItem::EnumDef(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<FnDef> for ModuleItem {
2019-08-18 20:36:22 +00:00
fn from(node: FnDef) -> ModuleItem {
ModuleItem::FnDef(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<TraitDef> for ModuleItem {
2019-08-18 20:36:22 +00:00
fn from(node: TraitDef) -> ModuleItem {
ModuleItem::TraitDef(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<TypeAliasDef> for ModuleItem {
2019-08-18 20:36:22 +00:00
fn from(node: TypeAliasDef) -> ModuleItem {
ModuleItem::TypeAliasDef(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<ImplBlock> for ModuleItem {
2019-08-18 20:36:22 +00:00
fn from(node: ImplBlock) -> ModuleItem {
ModuleItem::ImplBlock(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<UseItem> for ModuleItem {
2019-08-18 20:36:22 +00:00
fn from(node: UseItem) -> ModuleItem {
ModuleItem::UseItem(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<ExternCrateItem> for ModuleItem {
2019-08-18 20:36:22 +00:00
fn from(node: ExternCrateItem) -> ModuleItem {
ModuleItem::ExternCrateItem(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<ConstDef> for ModuleItem {
2019-08-18 20:36:22 +00:00
fn from(node: ConstDef) -> ModuleItem {
ModuleItem::ConstDef(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<StaticDef> for ModuleItem {
2019-08-18 20:36:22 +00:00
fn from(node: StaticDef) -> ModuleItem {
ModuleItem::StaticDef(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<Module> for ModuleItem {
2019-08-18 20:36:22 +00:00
fn from(node: Module) -> ModuleItem {
ModuleItem::Module(node)
2019-08-18 20:36:22 +00:00
}
}
impl AstNode for ModuleItem {
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
STRUCT_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 }),
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::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,
2019-01-07 13:16:02 +00:00
}
}
}
impl ast::AttrsOwner for ModuleItem {}
2019-01-07 13:16:02 +00:00
impl ModuleItem {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct Name {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for Name {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
NAME => true,
_ => false,
2018-08-09 14:43:39 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl Name {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct NameRef {
pub(crate) syntax: SyntaxNode,
2018-08-13 13:35:17 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for NameRef {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
NAME_REF => true,
_ => false,
2018-08-13 13:35:17 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl NameRef {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct NeverType {
pub(crate) syntax: SyntaxNode,
2018-08-14 09:38:20 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for NeverType {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
NEVER_TYPE => true,
_ => false,
2018-08-14 09:38:20 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl NeverType {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum NominalDef {
2019-07-18 16:23:05 +00:00
StructDef(StructDef),
EnumDef(EnumDef),
2018-08-14 10:33:44 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<StructDef> for NominalDef {
2019-08-18 20:36:22 +00:00
fn from(node: StructDef) -> NominalDef {
NominalDef::StructDef(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<EnumDef> for NominalDef {
2019-08-18 20:36:22 +00:00
fn from(node: EnumDef) -> NominalDef {
NominalDef::EnumDef(node)
2019-08-18 20:36:22 +00:00
}
}
impl AstNode for NominalDef {
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
STRUCT_DEF | ENUM_DEF => true,
_ => false,
}
}
fn cast(syntax: SyntaxNode) -> Option<Self> {
let res = match syntax.kind() {
STRUCT_DEF => NominalDef::StructDef(StructDef { syntax }),
ENUM_DEF => NominalDef::EnumDef(EnumDef { syntax }),
_ => return None,
};
Some(res)
}
fn syntax(&self) -> &SyntaxNode {
match self {
NominalDef::StructDef(it) => &it.syntax,
NominalDef::EnumDef(it) => &it.syntax,
2018-08-14 10:33:44 +00:00
}
}
}
2019-01-07 13:16:02 +00:00
impl ast::NameOwner for NominalDef {}
impl ast::TypeParamsOwner for NominalDef {}
impl ast::AttrsOwner for NominalDef {}
impl NominalDef {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct Param {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for Param {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
PARAM => true,
_ => false,
2018-08-26 09:09:28 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
impl ast::TypeAscriptionOwner for Param {}
2019-08-07 16:42:28 +00:00
impl ast::AttrsOwner for Param {}
2019-01-07 13:16:02 +00:00
impl Param {
2019-07-18 16:23:05 +00:00
pub fn pat(&self) -> Option<Pat> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct ParamList {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for ParamList {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
PARAM_LIST => true,
_ => false,
2018-08-26 09:09:28 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl ParamList {
2019-08-18 20:36:22 +00:00
pub fn params(&self) -> AstChildren<Param> {
AstChildren::new(&self.syntax)
2018-08-26 09:09:28 +00:00
}
2019-07-18 16:23:05 +00:00
pub fn self_param(&self) -> Option<SelfParam> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-08-31 13:30:42 +00:00
}
2018-08-26 09:09:28 +00:00
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct ParenExpr {
pub(crate) syntax: SyntaxNode,
2018-08-25 10:42:40 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for ParenExpr {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
PAREN_EXPR => true,
_ => false,
2018-08-25 10:42:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl ParenExpr {
2019-07-18 16:23:05 +00:00
pub fn expr(&self) -> Option<Expr> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-12-20 20:56:28 +00:00
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct ParenType {
pub(crate) syntax: SyntaxNode,
2018-08-14 09:38:20 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for ParenType {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
PAREN_TYPE => true,
_ => false,
2018-08-14 09:38:20 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl ParenType {
2019-07-18 16:23:05 +00:00
pub fn type_ref(&self) -> Option<TypeRef> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Pat {
2019-07-18 16:23:05 +00:00
RefPat(RefPat),
2019-08-23 20:04:58 +00:00
BoxPat(BoxPat),
2019-07-18 16:23:05 +00:00
BindPat(BindPat),
PlaceholderPat(PlaceholderPat),
DotDotPat(DotDotPat),
2019-07-18 16:23:05 +00:00
PathPat(PathPat),
2019-08-23 12:55:21 +00:00
RecordPat(RecordPat),
2019-07-18 16:23:05 +00:00
TupleStructPat(TupleStructPat),
TuplePat(TuplePat),
SlicePat(SlicePat),
RangePat(RangePat),
LiteralPat(LiteralPat),
2019-01-07 13:16:02 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<RefPat> for Pat {
2019-08-18 20:36:22 +00:00
fn from(node: RefPat) -> Pat {
Pat::RefPat(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-08-23 20:04:58 +00:00
impl From<BoxPat> for Pat {
fn from(node: BoxPat) -> Pat {
Pat::BoxPat(node)
}
}
2019-07-18 16:23:05 +00:00
impl From<BindPat> for Pat {
2019-08-18 20:36:22 +00:00
fn from(node: BindPat) -> Pat {
Pat::BindPat(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<PlaceholderPat> for Pat {
2019-08-18 20:36:22 +00:00
fn from(node: PlaceholderPat) -> Pat {
Pat::PlaceholderPat(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
impl From<DotDotPat> for Pat {
fn from(node: DotDotPat) -> Pat {
Pat::DotDotPat(node)
}
}
2019-07-18 16:23:05 +00:00
impl From<PathPat> for Pat {
2019-08-18 20:36:22 +00:00
fn from(node: PathPat) -> Pat {
Pat::PathPat(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-08-23 12:55:21 +00:00
impl From<RecordPat> for Pat {
fn from(node: RecordPat) -> Pat {
Pat::RecordPat(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<TupleStructPat> for Pat {
2019-08-18 20:36:22 +00:00
fn from(node: TupleStructPat) -> Pat {
Pat::TupleStructPat(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<TuplePat> for Pat {
2019-08-18 20:36:22 +00:00
fn from(node: TuplePat) -> Pat {
Pat::TuplePat(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<SlicePat> for Pat {
2019-08-18 20:36:22 +00:00
fn from(node: SlicePat) -> Pat {
Pat::SlicePat(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<RangePat> for Pat {
2019-08-18 20:36:22 +00:00
fn from(node: RangePat) -> Pat {
Pat::RangePat(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<LiteralPat> for Pat {
2019-08-18 20:36:22 +00:00
fn from(node: LiteralPat) -> Pat {
Pat::LiteralPat(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
impl AstNode for Pat {
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 }),
2019-08-23 20:04:58 +00:00
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 }),
2019-08-23 12:55:21 +00:00
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,
2019-08-23 20:04:58 +00:00
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,
2019-08-23 12:55:21 +00:00
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,
2018-08-26 09:09:28 +00:00
}
}
}
2019-01-07 13:16:02 +00:00
impl Pat {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct Path {
pub(crate) syntax: SyntaxNode,
2018-08-30 17:03:18 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for Path {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
PATH => true,
_ => false,
2018-08-30 17:03:18 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl Path {
2019-07-18 16:23:05 +00:00
pub fn segment(&self) -> Option<PathSegment> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-08-30 17:37:33 +00:00
}
2019-07-18 16:23:05 +00:00
pub fn qualifier(&self) -> Option<Path> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-10-24 15:37:25 +00:00
}
2018-08-30 17:37:33 +00:00
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct PathExpr {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for PathExpr {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
PATH_EXPR => true,
_ => false,
2018-08-25 10:42:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl PathExpr {
2019-07-18 16:23:05 +00:00
pub fn path(&self) -> Option<Path> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct PathPat {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for PathPat {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
PATH_PAT => true,
_ => false,
2018-08-26 09:09:28 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-15 14:24:04 +00:00
impl PathPat {
2019-07-18 16:23:05 +00:00
pub fn path(&self) -> Option<Path> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2019-01-15 14:24:04 +00:00
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct PathSegment {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for PathSegment {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
PATH_SEGMENT => true,
_ => false,
2018-08-30 17:37:33 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl PathSegment {
2019-07-18 16:23:05 +00:00
pub fn name_ref(&self) -> Option<NameRef> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
2019-07-18 16:23:05 +00:00
pub fn type_arg_list(&self) -> Option<TypeArgList> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
2019-09-07 13:13:05 +00:00
pub fn param_list(&self) -> Option<ParamList> {
AstChildren::new(&self.syntax).next()
}
pub fn ret_type(&self) -> Option<RetType> {
AstChildren::new(&self.syntax).next()
}
2019-09-11 18:01:07 +00:00
pub fn path_type(&self) -> Option<PathType> {
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct PathType {
pub(crate) syntax: SyntaxNode,
2018-08-14 09:38:20 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for PathType {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
PATH_TYPE => true,
_ => false,
2018-08-14 09:38:20 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl PathType {
2019-07-18 16:23:05 +00:00
pub fn path(&self) -> Option<Path> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-12-22 21:17:55 +00:00
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct PlaceholderPat {
pub(crate) syntax: SyntaxNode,
2018-08-26 09:09:28 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for PlaceholderPat {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
PLACEHOLDER_PAT => true,
_ => false,
2018-08-26 09:09:28 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl PlaceholderPat {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct PlaceholderType {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for PlaceholderType {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
PLACEHOLDER_TYPE => true,
_ => false,
2018-08-14 09:38:20 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl PlaceholderType {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct PointerType {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for PointerType {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
POINTER_TYPE => true,
_ => false,
2018-08-14 09:38:20 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl PointerType {
2019-07-18 16:23:05 +00:00
pub fn type_ref(&self) -> Option<TypeRef> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-08-23 12:55:21 +00:00
pub struct PrefixExpr {
2019-01-07 13:16:02 +00:00
pub(crate) syntax: SyntaxNode,
}
2019-08-23 12:55:21 +00:00
impl AstNode for PrefixExpr {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
2019-08-23 12:55:21 +00:00
PREFIX_EXPR => true,
2019-07-19 15:22:00 +00:00
_ => false,
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-08-23 12:55:21 +00:00
impl PrefixExpr {
pub fn expr(&self) -> Option<Expr> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-08-23 12:55:21 +00:00
pub struct RangeExpr {
2019-01-07 13:16:02 +00:00
pub(crate) syntax: SyntaxNode,
}
2019-08-23 12:55:21 +00:00
impl AstNode for RangeExpr {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
2019-08-23 12:55:21 +00:00
RANGE_EXPR => true,
2019-07-19 15:22:00 +00:00
_ => false,
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-08-23 12:55:21 +00:00
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
}
}
2019-08-23 12:55:21 +00:00
impl RangePat {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-08-23 12:55:21 +00:00
pub struct RecordField {
2019-01-07 13:16:02 +00:00
pub(crate) syntax: SyntaxNode,
2018-08-25 10:42:40 +00:00
}
2019-08-23 12:55:21 +00:00
impl AstNode for RecordField {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
2019-08-23 12:55:21 +00:00
RECORD_FIELD => true,
2019-07-19 15:22:00 +00:00
_ => false,
2018-08-25 10:42:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-08-23 12:55:21 +00:00
impl RecordField {
pub fn name_ref(&self) -> Option<NameRef> {
AstChildren::new(&self.syntax).next()
}
2019-07-18 16:23:05 +00:00
pub fn expr(&self) -> Option<Expr> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-12-20 20:56:28 +00:00
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-08-23 12:55:21 +00:00
pub struct RecordFieldDef {
2019-01-07 13:16:02 +00:00
pub(crate) syntax: SyntaxNode,
2018-08-25 10:42:40 +00:00
}
2019-08-23 12:55:21 +00:00
impl AstNode for RecordFieldDef {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
2019-08-23 12:55:21 +00:00
RECORD_FIELD_DEF => true,
2019-07-19 15:22:00 +00:00
_ => false,
2018-08-25 10:42:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-08-23 12:55:21 +00:00
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 {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-08-23 12:55:21 +00:00
pub struct RecordFieldDefList {
2019-01-07 13:16:02 +00:00
pub(crate) syntax: SyntaxNode,
2018-08-26 09:09:28 +00:00
}
2019-08-23 12:55:21 +00:00
impl AstNode for RecordFieldDefList {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
2019-08-23 12:55:21 +00:00
RECORD_FIELD_DEF_LIST => true,
2019-07-19 15:22:00 +00:00
_ => false,
2018-08-26 09:09:28 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-08-23 12:55:21 +00:00
impl RecordFieldDefList {
pub fn fields(&self) -> AstChildren<RecordFieldDef> {
AstChildren::new(&self.syntax)
}
}
#[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
}
}
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,
}
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()
}
}
#[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 cast(syntax: SyntaxNode) -> Option<Self> {
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
}
}
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)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct RecordLit {
pub(crate) syntax: SyntaxNode,
}
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 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
}
}
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()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct RefExpr {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for RefExpr {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
REF_EXPR => true,
_ => false,
2018-08-25 10:42:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl RefExpr {
2019-07-18 16:23:05 +00:00
pub fn expr(&self) -> Option<Expr> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-12-20 20:56:28 +00:00
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct RefPat {
pub(crate) syntax: SyntaxNode,
2018-08-26 09:09:28 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for RefPat {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
REF_PAT => true,
_ => false,
2018-08-26 09:09:28 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-13 10:34:57 +00:00
impl RefPat {
2019-07-18 16:23:05 +00:00
pub fn pat(&self) -> Option<Pat> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2019-01-13 10:34:57 +00:00
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct ReferenceType {
pub(crate) syntax: SyntaxNode,
2018-08-14 09:38:20 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for ReferenceType {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
REFERENCE_TYPE => true,
_ => false,
2018-08-14 09:38:20 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl ReferenceType {
2019-07-18 16:23:05 +00:00
pub fn type_ref(&self) -> Option<TypeRef> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct RetType {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for RetType {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
RET_TYPE => true,
_ => false,
2018-08-28 18:11:17 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl RetType {
2019-07-18 16:23:05 +00:00
pub fn type_ref(&self) -> Option<TypeRef> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct ReturnExpr {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for ReturnExpr {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
RETURN_EXPR => true,
_ => false,
2018-08-25 10:42:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl ReturnExpr {
2019-07-18 16:23:05 +00:00
pub fn expr(&self) -> Option<Expr> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-12-20 20:56:28 +00:00
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct SelfParam {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for SelfParam {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
SELF_PARAM => true,
_ => false,
2018-08-31 13:30:42 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
impl ast::TypeAscriptionOwner for SelfParam {}
2019-08-07 16:42:28 +00:00
impl ast::AttrsOwner for SelfParam {}
2019-03-30 10:25:53 +00:00
impl SelfParam {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct SlicePat {
pub(crate) syntax: SyntaxNode,
2018-08-26 09:09:28 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for SlicePat {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
SLICE_PAT => true,
_ => false,
2018-08-26 09:09:28 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl SlicePat {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct SliceType {
pub(crate) syntax: SyntaxNode,
2018-08-14 09:38:20 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for SliceType {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
SLICE_TYPE => true,
_ => false,
2018-08-14 09:38:20 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl SliceType {
2019-07-18 16:23:05 +00:00
pub fn type_ref(&self) -> Option<TypeRef> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct SourceFile {
pub(crate) syntax: SyntaxNode,
2018-11-07 15:38:43 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for SourceFile {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
SOURCE_FILE => true,
_ => false,
2018-11-07 15:38:43 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl ast::ModuleItemOwner for SourceFile {}
impl ast::FnDefOwner for SourceFile {}
impl SourceFile {
2019-08-18 20:36:22 +00:00
pub fn modules(&self) -> AstChildren<Module> {
AstChildren::new(&self.syntax)
2018-11-07 15:38:43 +00:00
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct StaticDef {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for StaticDef {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
STATIC_DEF => true,
_ => false,
2018-08-11 08:03:22 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
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 {
2019-07-18 16:23:05 +00:00
pub fn body(&self) -> Option<Expr> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Stmt {
2019-07-18 16:23:05 +00:00
ExprStmt(ExprStmt),
LetStmt(LetStmt),
2018-08-27 07:12:28 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<ExprStmt> for Stmt {
2019-08-18 20:36:22 +00:00
fn from(node: ExprStmt) -> Stmt {
Stmt::ExprStmt(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<LetStmt> for Stmt {
2019-08-18 20:36:22 +00:00
fn from(node: LetStmt) -> Stmt {
Stmt::LetStmt(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
impl AstNode for Stmt {
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
EXPR_STMT | LET_STMT => true,
_ => false,
}
}
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,
2018-08-27 07:12:28 +00:00
}
}
}
2019-01-07 13:16:02 +00:00
impl Stmt {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct StructDef {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for StructDef {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
STRUCT_DEF => true,
_ => false,
2018-08-11 07:56:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
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 {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-08-23 12:55:21 +00:00
pub struct TokenTree {
2019-01-07 13:16:02 +00:00
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-08-23 12:55:21 +00:00
impl AstNode for TokenTree {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
2019-08-23 12:55:21 +00:00
TOKEN_TREE => true,
2019-07-19 15:22:00 +00:00
_ => false,
2018-08-25 10:42:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-08-23 12:55:21 +00:00
impl TokenTree {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-08-23 12:55:21 +00:00
pub struct TraitDef {
2019-01-07 13:16:02 +00:00
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-08-23 12:55:21 +00:00
impl AstNode for TraitDef {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
2019-08-23 12:55:21 +00:00
TRAIT_DEF => true,
2019-07-19 15:22:00 +00:00
_ => false,
2018-08-26 09:09:28 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-08-23 12:55:21 +00:00
impl ast::VisibilityOwner for TraitDef {}
impl ast::NameOwner for TraitDef {}
impl ast::AttrsOwner for TraitDef {}
impl ast::DocCommentsOwner for TraitDef {}
impl ast::TypeParamsOwner for TraitDef {}
impl ast::TypeBoundsOwner for TraitDef {}
impl TraitDef {
pub fn item_list(&self) -> Option<ItemList> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-08-23 12:55:21 +00:00
pub struct TryBlockExpr {
2019-01-07 13:16:02 +00:00
pub(crate) syntax: SyntaxNode,
2018-08-16 09:51:40 +00:00
}
2019-08-23 12:55:21 +00:00
impl AstNode for TryBlockExpr {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
2019-08-23 12:55:21 +00:00
TRY_BLOCK_EXPR => true,
2019-07-19 15:22:00 +00:00
_ => false,
2018-08-16 09:51:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-09-02 16:45:41 +00:00
impl TryBlockExpr {
2019-09-02 18:23:19 +00:00
pub fn body(&self) -> Option<BlockExpr> {
2019-09-02 16:45:41 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-08-23 12:55:21 +00:00
pub struct TryExpr {
2019-01-07 13:16:02 +00:00
pub(crate) syntax: SyntaxNode,
2018-08-11 08:03:22 +00:00
}
2019-08-23 12:55:21 +00:00
impl AstNode for TryExpr {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
2019-08-23 12:55:21 +00:00
TRY_EXPR => true,
2019-07-19 15:22:00 +00:00
_ => false,
2018-08-11 08:03:22 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-08-23 12:55:21 +00:00
impl TryExpr {
pub fn expr(&self) -> Option<Expr> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2019-03-24 16:36:15 +00:00
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-08-23 12:55:21 +00:00
pub struct TupleExpr {
2019-06-06 11:36:16 +00:00
pub(crate) syntax: SyntaxNode,
}
2019-08-23 12:55:21 +00:00
impl AstNode for TupleExpr {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
2019-08-23 12:55:21 +00:00
TUPLE_EXPR => true,
2019-07-19 15:22:00 +00:00
_ => false,
2019-06-06 11:36:16 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
2019-06-06 11:36:16 +00:00
}
2019-08-23 12:55:21 +00:00
impl TupleExpr {
pub fn exprs(&self) -> AstChildren<Expr> {
AstChildren::new(&self.syntax)
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-08-23 12:55:21 +00:00
pub struct TupleFieldDef {
2019-01-07 13:16:02 +00:00
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-08-23 12:55:21 +00:00
impl AstNode for TupleFieldDef {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
2019-08-23 12:55:21 +00:00
TUPLE_FIELD_DEF => true,
2019-07-19 15:22:00 +00:00
_ => false,
2018-08-25 10:42:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-08-23 12:55:21 +00:00
impl ast::VisibilityOwner for TupleFieldDef {}
impl ast::AttrsOwner for TupleFieldDef {}
impl TupleFieldDef {
pub fn type_ref(&self) -> Option<TypeRef> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-12-20 20:56:28 +00:00
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-08-23 12:55:21 +00:00
pub struct TupleFieldDefList {
2019-01-07 13:16:02 +00:00
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-08-23 12:55:21 +00:00
impl AstNode for TupleFieldDefList {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
2019-08-23 12:55:21 +00:00
TUPLE_FIELD_DEF_LIST => true,
2019-07-19 15:22:00 +00:00
_ => false,
2018-08-25 10:42:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-08-23 12:55:21 +00:00
impl TupleFieldDefList {
pub fn fields(&self) -> AstChildren<TupleFieldDef> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax)
2019-01-13 11:52:25 +00:00
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct TuplePat {
pub(crate) syntax: SyntaxNode,
2018-08-26 09:09:28 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for TuplePat {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
TUPLE_PAT => true,
_ => false,
2018-08-26 09:09:28 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-15 14:24:04 +00:00
impl TuplePat {
2019-08-18 20:36:22 +00:00
pub fn args(&self) -> AstChildren<Pat> {
AstChildren::new(&self.syntax)
2019-01-15 14:24:04 +00:00
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct TupleStructPat {
pub(crate) syntax: SyntaxNode,
2018-08-26 09:09:28 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for TupleStructPat {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
TUPLE_STRUCT_PAT => true,
_ => false,
2018-08-26 09:09:28 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl TupleStructPat {
2019-08-18 20:36:22 +00:00
pub fn args(&self) -> AstChildren<Pat> {
AstChildren::new(&self.syntax)
}
2019-07-18 16:23:05 +00:00
pub fn path(&self) -> Option<Path> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct TupleType {
pub(crate) syntax: SyntaxNode,
2018-08-14 09:38:20 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for TupleType {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
TUPLE_TYPE => true,
_ => false,
2018-08-14 09:38:20 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl TupleType {
2019-08-18 20:36:22 +00:00
pub fn fields(&self) -> AstChildren<TypeRef> {
AstChildren::new(&self.syntax)
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TypeAliasDef {
pub(crate) syntax: SyntaxNode,
}
impl AstNode for TypeAliasDef {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
TYPE_ALIAS_DEF => true,
_ => false,
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
impl ast::VisibilityOwner for TypeAliasDef {}
impl ast::NameOwner for TypeAliasDef {}
impl ast::TypeParamsOwner for TypeAliasDef {}
impl ast::AttrsOwner for TypeAliasDef {}
impl ast::DocCommentsOwner for TypeAliasDef {}
2019-03-31 07:56:48 +00:00
impl ast::TypeBoundsOwner for TypeAliasDef {}
impl TypeAliasDef {
2019-07-18 16:23:05 +00:00
pub fn type_ref(&self) -> Option<TypeRef> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TypeArg {
pub(crate) syntax: SyntaxNode,
}
impl AstNode for TypeArg {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
TYPE_ARG => true,
_ => false,
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
impl TypeArg {
2019-07-18 16:23:05 +00:00
pub fn type_ref(&self) -> Option<TypeRef> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TypeArgList {
pub(crate) syntax: SyntaxNode,
}
impl AstNode for TypeArgList {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
TYPE_ARG_LIST => true,
_ => false,
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
impl TypeArgList {
2019-08-18 20:36:22 +00:00
pub fn type_args(&self) -> AstChildren<TypeArg> {
AstChildren::new(&self.syntax)
}
2019-08-18 20:36:22 +00:00
pub fn lifetime_args(&self) -> AstChildren<LifetimeArg> {
AstChildren::new(&self.syntax)
}
2019-08-18 20:36:22 +00:00
pub fn assoc_type_args(&self) -> AstChildren<AssocTypeArg> {
AstChildren::new(&self.syntax)
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TypeBound {
pub(crate) syntax: SyntaxNode,
}
impl AstNode for TypeBound {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
TYPE_BOUND => true,
_ => false,
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
impl TypeBound {
2019-07-18 16:23:05 +00:00
pub fn type_ref(&self) -> Option<TypeRef> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TypeBoundList {
pub(crate) syntax: SyntaxNode,
}
impl AstNode for TypeBoundList {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
TYPE_BOUND_LIST => true,
_ => false,
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
impl TypeBoundList {
2019-08-18 20:36:22 +00:00
pub fn bounds(&self) -> AstChildren<TypeBound> {
AstChildren::new(&self.syntax)
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct TypeParam {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for TypeParam {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
TYPE_PARAM => true,
_ => false,
2018-08-22 16:02:37 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl ast::NameOwner for TypeParam {}
impl ast::AttrsOwner for TypeParam {}
2019-03-31 07:56:48 +00:00
impl ast::TypeBoundsOwner for TypeParam {}
2019-11-20 08:42:58 +00:00
impl TypeParam {
pub fn default_type(&self) -> Option<TypeRef> {
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct TypeParamList {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for TypeParamList {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
TYPE_PARAM_LIST => true,
_ => false,
2018-08-22 13:46:42 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl TypeParamList {
2019-08-18 20:36:22 +00:00
pub fn type_params(&self) -> AstChildren<TypeParam> {
AstChildren::new(&self.syntax)
2018-08-22 16:02:37 +00:00
}
2019-08-18 20:36:22 +00:00
pub fn lifetime_params(&self) -> AstChildren<LifetimeParam> {
AstChildren::new(&self.syntax)
2018-08-28 20:59:57 +00:00
}
2018-08-22 16:02:37 +00:00
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum TypeRef {
2019-07-18 16:23:05 +00:00
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),
2019-01-07 13:16:02 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<ParenType> for TypeRef {
2019-08-18 20:36:22 +00:00
fn from(node: ParenType) -> TypeRef {
TypeRef::ParenType(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<TupleType> for TypeRef {
2019-08-18 20:36:22 +00:00
fn from(node: TupleType) -> TypeRef {
TypeRef::TupleType(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<NeverType> for TypeRef {
2019-08-18 20:36:22 +00:00
fn from(node: NeverType) -> TypeRef {
TypeRef::NeverType(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<PathType> for TypeRef {
2019-08-18 20:36:22 +00:00
fn from(node: PathType) -> TypeRef {
TypeRef::PathType(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<PointerType> for TypeRef {
2019-08-18 20:36:22 +00:00
fn from(node: PointerType) -> TypeRef {
TypeRef::PointerType(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<ArrayType> for TypeRef {
2019-08-18 20:36:22 +00:00
fn from(node: ArrayType) -> TypeRef {
TypeRef::ArrayType(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<SliceType> for TypeRef {
2019-08-18 20:36:22 +00:00
fn from(node: SliceType) -> TypeRef {
TypeRef::SliceType(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<ReferenceType> for TypeRef {
2019-08-18 20:36:22 +00:00
fn from(node: ReferenceType) -> TypeRef {
TypeRef::ReferenceType(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<PlaceholderType> for TypeRef {
2019-08-18 20:36:22 +00:00
fn from(node: PlaceholderType) -> TypeRef {
TypeRef::PlaceholderType(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<FnPointerType> for TypeRef {
2019-08-18 20:36:22 +00:00
fn from(node: FnPointerType) -> TypeRef {
TypeRef::FnPointerType(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<ForType> for TypeRef {
2019-08-18 20:36:22 +00:00
fn from(node: ForType) -> TypeRef {
TypeRef::ForType(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<ImplTraitType> for TypeRef {
2019-08-18 20:36:22 +00:00
fn from(node: ImplTraitType) -> TypeRef {
TypeRef::ImplTraitType(node)
2019-08-18 20:36:22 +00:00
}
2019-02-24 13:57:05 +00:00
}
2019-07-18 16:23:05 +00:00
impl From<DynTraitType> for TypeRef {
2019-08-18 20:36:22 +00:00
fn from(node: DynTraitType) -> TypeRef {
TypeRef::DynTraitType(node)
}
}
impl AstNode for TypeRef {
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,
2019-01-07 13:16:02 +00:00
}
}
}
impl TypeRef {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct UnionDef {
pub(crate) syntax: SyntaxNode,
}
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 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 {}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct UseItem {
pub(crate) syntax: SyntaxNode,
2018-08-28 08:12:42 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for UseItem {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
USE_ITEM => true,
_ => false,
2018-08-28 08:12:42 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-02-10 19:44:34 +00:00
impl ast::AttrsOwner for UseItem {}
2019-01-07 13:16:02 +00:00
impl UseItem {
2019-07-18 16:23:05 +00:00
pub fn use_tree(&self) -> Option<UseTree> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct UseTree {
pub(crate) syntax: SyntaxNode,
2018-08-30 17:37:33 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for UseTree {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
USE_TREE => true,
_ => false,
2018-08-30 17:37:33 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl UseTree {
2019-07-18 16:23:05 +00:00
pub fn path(&self) -> Option<Path> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-08-30 17:37:33 +00:00
}
2019-07-18 16:23:05 +00:00
pub fn use_tree_list(&self) -> Option<UseTreeList> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-08-30 17:37:33 +00:00
}
2019-07-18 16:23:05 +00:00
pub fn alias(&self) -> Option<Alias> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2019-02-01 23:18:10 +00:00
}
2018-08-30 17:37:33 +00:00
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct UseTreeList {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for UseTreeList {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
USE_TREE_LIST => true,
_ => false,
2018-08-30 17:37:33 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl UseTreeList {
2019-08-18 20:36:22 +00:00
pub fn use_trees(&self) -> AstChildren<UseTree> {
AstChildren::new(&self.syntax)
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct Visibility {
pub(crate) syntax: SyntaxNode,
2019-01-03 10:47:28 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for Visibility {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
VISIBILITY => true,
_ => false,
2019-01-03 10:47:28 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl Visibility {}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct WhereClause {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for WhereClause {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
WHERE_CLAUSE => true,
_ => false,
2018-08-22 08:56:36 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
impl WhereClause {
2019-08-18 20:36:22 +00:00
pub fn predicates(&self) -> AstChildren<WherePred> {
AstChildren::new(&self.syntax)
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct WherePred {
pub(crate) syntax: SyntaxNode,
}
impl AstNode for WherePred {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
WHERE_PRED => true,
_ => false,
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
impl ast::TypeBoundsOwner for WherePred {}
impl WherePred {
2019-07-18 16:23:05 +00:00
pub fn type_ref(&self) -> Option<TypeRef> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
}
}
2019-07-18 16:23:05 +00:00
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2019-01-07 13:16:02 +00:00
pub struct WhileExpr {
pub(crate) syntax: SyntaxNode,
2018-11-06 19:47:38 +00:00
}
2019-01-07 13:16:02 +00:00
impl AstNode for WhileExpr {
2019-07-19 15:22:00 +00:00
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
WHILE_EXPR => true,
_ => false,
2018-08-25 10:42:40 +00:00
}
}
2019-07-19 15:22:00 +00:00
fn cast(syntax: SyntaxNode) -> Option<Self> {
2019-08-18 20:36:22 +00:00
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
2019-07-19 15:22:00 +00:00
}
}
2019-01-07 13:16:02 +00:00
impl ast::LoopBodyOwner for WhileExpr {}
impl WhileExpr {
2019-07-18 16:23:05 +00:00
pub fn condition(&self) -> Option<Condition> {
2019-08-18 20:36:22 +00:00
AstChildren::new(&self.syntax).next()
2018-08-27 09:22:09 +00:00
}
}