Skip to main content

oak_rust/language/
mod.rs

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