Skip to main content

oak_rust/language/
mod.rs

1#[doc = include_str!("readme.md")]
2use crate::{ast::RustRoot, lexer::RustTokenType, parser::RustElementType};
3use oak_core::{Language, LanguageCategory};
4use serde::{Deserialize, Serialize};
5
6/// Rust 语言配置和元数据。
7#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
8pub struct RustLanguage {
9    /// Allow using `unsafe` blocks and functions
10    pub allow_unsafe: bool,
11    /// Allow using `async` functions and blocks
12    pub allow_async: bool,
13    /// Enable experimental features
14    pub experimental_features: bool,
15}
16
17impl RustLanguage {
18    /// 创建新的 Rust 语言配置
19    pub fn new() -> Self {
20        Self::default()
21    }
22}
23
24impl Default for RustLanguage {
25    fn default() -> Self {
26        Self { allow_unsafe: true, allow_async: true, experimental_features: false }
27    }
28}
29
30impl Language for RustLanguage {
31    const NAME: &'static str = "rust";
32    const CATEGORY: LanguageCategory = LanguageCategory::Programming;
33
34    type TokenType = RustTokenType;
35    type ElementType = RustElementType;
36    type TypedRoot = RustRoot;
37}