pub enum RustElementType {
Show 73 variants
SourceFile,
Function,
Trait,
Impl,
UseItem,
Static,
Const,
TypeAlias,
Macro,
ExternCrate,
ExternBlock,
ModuleItem,
StructItem,
EnumItem,
ReturnStatement,
ParameterList,
Parameter,
ReturnType,
LetStatement,
ExpressionStatement,
BlockExpression,
IfExpression,
MatchExpression,
LoopExpression,
WhileExpression,
ForExpression,
IdentifierExpression,
LiteralExpression,
PathExpression,
IntegerLiteral,
FloatLiteral,
StringLiteral,
CharLiteral,
BooleanLiteral,
ParenthesizedExpression,
TupleExpression,
ArrayExpression,
StructExpression,
AssignmentExpression,
CallExpression,
MethodCallExpression,
FieldExpression,
IndexExpression,
ReturnExpression,
BreakExpression,
ContinueExpression,
Pattern,
MatchArm,
Type,
PathType,
TupleType,
ArrayType,
SliceType,
ReferenceType,
PointerType,
FunctionType,
GenericParams,
GenericArgs,
WhereClause,
Attribute,
Visibility,
Async,
Unsafe,
Extern,
Identifier,
Expression,
BinaryExpression,
UnaryExpression,
ItemStatement,
ArgumentList,
PubItem,
Block,
Error,
}Expand description
Rust 语法树中所有可能的元素类型。
Variants§
SourceFile
The root element of any Rust source file
// Entire file content
fn main() {}Function
A function definition
fn add(a: i32, b: i32) -> i32 {
a + b
}Trait
A trait definition
trait Display {
fn fmt(&self) -> String;
}Impl
An impl block
impl Display for Point {
fn fmt(&self, f: &mut Formatter) -> Result { /* ... */ }
}UseItem
A use statement
use std::collections::HashMap;Static
A static variable
static COUNT: i32 = 0;Const
A constant
const MAX_SIZE: usize = 100;TypeAlias
A type alias
type MyResult = Result<i32, String>;Macro
A macro invocation or definition
println!("Hello, {}!", name);
vec![1, 2, 3]ExternCrate
An extern crate declaration
extern crate serde;ExternBlock
An extern block
extern "C" {
fn call_c_function();
}ModuleItem
A module item
mod my_module;
mod my_module { /* content */ }StructItem
A struct definition
struct Point {
x: f64,
y: f64,
}EnumItem
An enum definition
enum Color {
Red,
Green,
Blue,
}ReturnStatement
A return statement
return 42;ParameterList
A parameter list in function definitions
fn example(a: i32, b: String) // (a: i32, b: String)Parameter
A single parameter in a function
fn example(x: i32) // x: i32ReturnType
A return type annotation
fn example() -> i32 // -> i32LetStatement
A let statement
let x = 42;
let mut y: String = "hello".to_string();ExpressionStatement
An expression used as a statement
x + 1; // Expression statementBlockExpression
A block expression
{
let x = 1;
x + 2
}IfExpression
An if expression
if x > 0 { "positive" } else { "non-positive" }MatchExpression
A match expression
match x {
1 => "one",
2 => "two",
_ => "other",
}LoopExpression
A loop expression
loop {
println!("infinite loop");
}WhileExpression
A while loop
while x < 10 {
x += 1;
}ForExpression
A for loop
for item in collection {
println!("{}", item);
}IdentifierExpression
A variable or identifier expression
let name = x; // x is an identifier expressionLiteralExpression
A literal expression (any literal value)
let x = 42; // 42 is a literal expressionPathExpression
A path expression
std::collections::HashMap::new()IntegerLiteral
An integer literal
42, -10, 0xFF, 0b1010FloatLiteral
A floating-point literal
3.14, -2.5, 1e10StringLiteral
A string literal
"hello", "world\n", r#"raw string"#CharLiteral
A character literal
'a', '\n', '🦀'BooleanLiteral
A boolean literal
true, falseParenthesizedExpression
A parenthesized expression
(x + 1) * 2TupleExpression
A tuple expression
(1, "hello", 3.14)ArrayExpression
An array expression
[1, 2, 3, 4, 5]StructExpression
A struct expression (struct instantiation)
Point { x: 1.0, y: 2.0 }AssignmentExpression
An assignment expression
x = 42CallExpression
A function call expression
println!("Hello!")MethodCallExpression
A method call expression
string.trim().to_uppercase()FieldExpression
A field access expression
point.x, user.nameIndexExpression
An index expression
array[0], vector[1..3]ReturnExpression
A return expression
return 42;BreakExpression
A break expression
break;
break 42;ContinueExpression
A continue expression
continue;Pattern
A pattern (used in match, let, etc.)
Some(x), Ok(value), Point { x, y }MatchArm
A match arm
1 => "one", // pattern => expressionType
A type annotation
i32, String, Vec<T>PathType
A path type
std::collections::HashMap<K, V>TupleType
A tuple type
(i32, String)ArrayType
An array type
[i32; 10]SliceType
A slice type
[i32], strReferenceType
A reference type
&str, &mut i32PointerType
A raw pointer type
*const i32, *mut StringFunctionType
A function type
fn(i32) -> StringGenericParams
Generic parameters
fn example<T, U>(x: T) -> U
^^^^^^ generic parametersGenericArgs
Generic arguments
Vec<i32>, Option<String>
^^^ generic argumentsWhereClause
A where clause
where T: Display + Clone, U: DebugAttribute
An attribute
#[derive(Debug)]
#[inline]Visibility
A visibility modifier
pub, pub(crate), private (no modifier)Async
The async keyword
async fn example() {}Unsafe
The unsafe keyword
unsafe fn example() {}Extern
The extern keyword
extern "C" fn example();Identifier
An identifier
variable_name, function_name, TypeNameExpression
A generic expression (catch-all for expressions)
Any expression that doesn't fit specific categoriesBinaryExpression
A binary expression
x + y, a && b, count > 0UnaryExpression
A unary expression
!flag, -number, *pointerItemStatement
An item used as a statement
fn nested() {}ArgumentList
An argument list in function calls
example(1, "hello", true)PubItem
A public item
pub struct PublicStruct;Block
A block expression
{
statements;
expr
}Error
Represents a syntax error in the parsed code
Invalid or unparseable syntaxTrait Implementations§
Source§impl Clone for RustElementType
impl Clone for RustElementType
Source§fn clone(&self) -> RustElementType
fn clone(&self) -> RustElementType
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more