Expand description
Strongly-typed AST types for Rust, auto-generated from
tree-sitter-rust’s node-types.json.
This crate is generated by treesitter-types and is
automatically kept up to date when a new version of the grammar crate is released.
These types have been tested by parsing the Rust compiler source code.
See the Tree-sitter project for more information about the underlying parser framework.
§Example
use treesitter_types_rust::*;
// A minimal Rust hello-world program.
let src = b"\
fn main() {
println!(\"Hello, World!\");
}
";
// Parse the source with tree-sitter and convert into typed AST.
let mut parser = tree_sitter::Parser::new();
parser.set_language(&tree_sitter_rust::LANGUAGE.into()).unwrap();
let tree = parser.parse(src, None).unwrap();
let source_file = SourceFile::from_node(tree.root_node(), src).unwrap();
// The source file has one top-level child: a function definition.
assert_eq!(source_file.children.len(), 1);
// Unwrap the function item through the declaration statement wrapper.
let SourceFileChildren::DeclarationStatement(decl) = &source_file.children[0] else {
panic!("expected a declaration statement");
};
let DeclarationStatement::FunctionItem(func) = decl.as_ref() else {
panic!("expected a function item");
};
// Check function metadata.
let FunctionItemName::Identifier(name) = &func.name else {
panic!("expected an identifier");
};
assert_eq!(name.text(), "main");
assert!(func.parameters.children.is_empty()); // no parameters
assert!(func.return_type.is_none()); // no return type
// The body contains one statement: the `println!` macro invocation.
assert_eq!(func.body.children.len(), 1);Re-exports§
pub use tree_sitter_rust;pub use treesitter_types::tree_sitter;
Structs§
- Abstract
Type - Arguments
- Array
Expression - Array
Type - Assignment
Expression - Associated
Type - Async
Block - Attribute
- Attribute
Item - Await
Expression - Base
Field Initializer - Binary
Expression - Block
- Block
Comment - Boolean
Literal - Bounded
Type - Bracketed
Type - Break
Expression - Call
Expression - Captured
Pattern - Char
Literal - Closure
Expression - Closure
Parameters - Compound
Assignment Expr - Const
Block - Const
Item - Const
Parameter - Continue
Expression - Crate
- Declaration
List - DocComment
- Dynamic
Type - Else
Clause - Empty
Statement - Enum
Item - Enum
Variant - Enum
Variant List - Escape
Sequence - Expression
Statement - Extern
Crate Declaration - Extern
Modifier - Field
Declaration - Field
Declaration List - Field
Expression - Field
Identifier - Field
Initializer - Field
Initializer List - Field
Pattern - Float
Literal - ForExpression
- ForLifetimes
- Foreign
ModItem - Fragment
Specifier - Function
Item - Function
Modifiers - Function
Signature Item - Function
Type - GenBlock
- Generic
Function - Generic
Pattern - Generic
Type - Generic
Type With Turbofish - Higher
Ranked Trait Bound - Identifier
- IfExpression
- Impl
Item - Index
Expression - Inner
Attribute Item - Inner
DocComment Marker - Integer
Literal - Label
- LetChain
- LetCondition
- LetDeclaration
- Lifetime
- Lifetime
Parameter - Line
Comment - Loop
Expression - Macro
Definition - Macro
Invocation - Macro
Rule - Match
Arm - Match
Block - Match
Expression - Match
Pattern - Metavariable
- ModItem
- MutPattern
- Mutable
Specifier - Negative
Literal - Never
Type - OrPattern
- Ordered
Field Declaration List - Outer
DocComment Marker - Parameter
- Parameters
- Parenthesized
Expression - Pointer
Type - Primitive
Type - Qualified
Type - Range
Expression - Range
Pattern - RawString
Literal - RefPattern
- Reference
Expression - Reference
Pattern - Reference
Type - Remaining
Field Pattern - Removed
Trait Bound - Return
Expression - Scoped
Identifier - Scoped
Type Identifier - Scoped
UseList - Self
Parameter - Self
Type - Shebang
- Shorthand
Field Identifier - Shorthand
Field Initializer - Slice
Pattern - Source
File - Span
- Static
Item - String
Content - String
Literal - Struct
Expression - Struct
Item - Struct
Pattern - Super
- Token
Binding Pattern - Token
Repetition - Token
Repetition Pattern - Token
Tree - Token
Tree Pattern - Trait
Bounds - Trait
Item - TryBlock
- TryExpression
- Tuple
Expression - Tuple
Pattern - Tuple
Struct Pattern - Tuple
Type - Type
Arguments - Type
Binding - Type
Cast Expression - Type
Identifier - Type
Item - Type
Parameter - Type
Parameters - Unary
Expression - Union
Item - Unit
Expression - Unit
Type - Unsafe
Block - UseAs
Clause - UseBounds
- UseDeclaration
- UseList
- UseWildcard
- Variadic
Parameter - Visibility
Modifier - Where
Clause - Where
Predicate - While
Expression - Yield
Expression
Enums§
- Abstract
Type Trait - AnyNode
- Arguments
Children - Array
Expression Children - Attribute
Children - Binary
Expression Operator - Block
Children - Bounded
Type Children - Bracketed
Type Children - Break
Expression Children - Call
Expression Function - Closure
Expression Body - Closure
Parameters Children - Compound
Assignment Expr Operator - Const
Parameter Value - Declaration
Statement - Dynamic
Type Trait - Else
Clause Children - Enum
Item Children - Enum
Variant Body - Enum
Variant List Children - Expression
- Extern
Crate Declaration Children - Field
Declaration List Children - Field
Expression Field - Field
Initializer Field - Field
Initializer List Children - Field
Pattern Name - Function
Item Children - Function
Item Name - Function
Signature Item Children - Function
Signature Item Name - Function
Type Children - Function
Type Trait - Generic
Function Function - Generic
Pattern Children - Generic
Type Type - Generic
Type With Turbofish Type - IfExpression
Condition - Impl
Item Trait - LetChain
Children - Literal
- Literal
Pattern - Macro
Invocation Macro - Match
ArmChildren - Match
Pattern Condition - MutPattern
Children - Negative
Literal Children - Ordered
Field Declaration List Children - Parameter
Pattern - Parameters
Children - Parse
Error - Pattern
- Range
Pattern Left - Range
Pattern Right - Reference
Pattern Children - Reference
Type Children - Scoped
Identifier Name - Scoped
Identifier Path - Scoped
Type Identifier Path - Scoped
UseList Path - Self
Parameter Children - Shorthand
Field Initializer Children - Source
File Children - Static
Item Children - String
Literal Children - Struct
Expression Name - Struct
Item Body - Struct
Item Children - Struct
Pattern Children - Struct
Pattern Type - Token
Repetition Children - Token
Repetition Pattern Children - Token
Tree Children - Token
Tree Pattern Children - Trait
Bounds Children - Trait
Item Children - Tuple
Expression Children - Tuple
Pattern Children - Tuple
Struct Pattern Type - Type
- Type
Arguments Children - Type
Item Children - Type
Parameters Children - Union
Item Children - UseAs
Clause Path - UseBounds
Children - UseDeclaration
Argument - UseList
Children - UseWildcard
Children - Visibility
Modifier Children - Where
Predicate Left - While
Expression Condition