Skip to main content

luaur_ast/methods/
printer_visualize_block_pretty_printer_alt_b.rs

1use crate::records::ast_stat::AstStat;
2use crate::records::ast_stat_block::AstStatBlock;
3use crate::records::printer::Printer;
4use crate::rtti::ast_node_as;
5
6pub trait IntoAstStatMut {
7    unsafe fn into_ast_stat_mut(self) -> *mut AstStat;
8}
9
10impl IntoAstStatMut for *mut AstStat {
11    unsafe fn into_ast_stat_mut(self) -> *mut AstStat {
12        self
13    }
14}
15
16impl IntoAstStatMut for &mut AstStat {
17    unsafe fn into_ast_stat_mut(self) -> *mut AstStat {
18        self
19    }
20}
21
22impl<'a> Printer<'a> {
23    pub fn visualize_block_ast_stat<S: IntoAstStatMut>(&mut self, stat: S) {
24        let stat = unsafe { stat.into_ast_stat_mut() };
25        let block = unsafe {
26            ast_node_as::<AstStatBlock>(
27                stat as *mut AstStat as *mut crate::records::ast_node::AstNode,
28            )
29        };
30        if !block.is_null() {
31            let block_ref = unsafe { &mut *block };
32            self.visualize_block_ast_stat_block(block_ref);
33            return;
34        }
35
36        luaur_common::LUAU_ASSERT!(false);
37    }
38}