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
5/// Configuration and metadata for the Rust language.
6#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::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    /// Creates a new default Rust language configuration.
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 = crate::lexer::RustTokenType;
35    type ElementType = crate::parser::RustElementType;
36    type TypedRoot = RustRoot;
37}