Skip to main content

RustElementType

Enum RustElementType 

Source
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: i32
§

ReturnType

A return type annotation

fn example() -> i32 // -> i32
§

LetStatement

A let statement

let x = 42;
let mut y: String = "hello".to_string();
§

ExpressionStatement

An expression used as a statement

x + 1; // Expression statement
§

BlockExpression

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 expression
§

LiteralExpression

A literal expression (any literal value)

let x = 42; // 42 is a literal expression
§

PathExpression

A path expression

std::collections::HashMap::new()
§

IntegerLiteral

An integer literal

42, -10, 0xFF, 0b1010
§

FloatLiteral

A floating-point literal

3.14, -2.5, 1e10
§

StringLiteral

A string literal

"hello", "world\n", r#"raw string"#
§

CharLiteral

A character literal

'a', '\n', '🦀'
§

BooleanLiteral

A boolean literal

true, false
§

ParenthesizedExpression

A parenthesized expression

(x + 1) * 2
§

TupleExpression

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 = 42
§

CallExpression

A function call expression

println!("Hello!")
§

MethodCallExpression

A method call expression

string.trim().to_uppercase()
§

FieldExpression

A field access expression

point.x, user.name
§

IndexExpression

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 => expression
§

Type

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], str
§

ReferenceType

A reference type

&str, &mut i32
§

PointerType

A raw pointer type

*const i32, *mut String
§

FunctionType

A function type

fn(i32) -> String
§

GenericParams

Generic parameters

fn example<T, U>(x: T) -> U
         ^^^^^^ generic parameters
§

GenericArgs

Generic arguments

Vec<i32>, Option<String>
    ^^^ generic arguments
§

WhereClause

A where clause

where T: Display + Clone, U: Debug
§

Attribute

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, TypeName
§

Expression

A generic expression (catch-all for expressions)

Any expression that doesn't fit specific categories
§

BinaryExpression

A binary expression

x + y, a && b, count > 0
§

UnaryExpression

A unary expression

!flag, -number, *pointer
§

ItemStatement

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 syntax

Trait Implementations§

Source§

impl Clone for RustElementType

Source§

fn clone(&self) -> RustElementType

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RustElementType

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for RustElementType

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl ElementType for RustElementType

Source§

type Role = UniversalElementRole

The associated role type for this element kind.
Source§

fn is_root(&self) -> bool

Returns true if this element represents the root of the parsed tree. Read more
Source§

fn is_error(&self) -> bool

Returns true if this element represents an error condition. Read more
Source§

fn role(&self) -> UniversalElementRole

Returns the general syntactic role of this element. Read more
Source§

fn is_role(&self, role: Self::Role) -> bool

Returns true if this element matches the specified language-specific role.
Source§

fn is_universal(&self, role: UniversalElementRole) -> bool

Returns true if this element matches the specified universal role.
Source§

impl From<RustTokenType> for RustElementType

Source§

fn from(token_type: RustTokenType) -> Self

Converts to this type from the input type.
Source§

impl Hash for RustElementType

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for RustElementType

Source§

fn eq(&self, other: &RustElementType) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for RustElementType

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for RustElementType

Source§

impl Eq for RustElementType

Source§

impl StructuralPartialEq for RustElementType

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,